[hg] main-silver: #227169: Be careful when creating service thre...

  • From:
  • To:
  • Subject: [hg] main-silver: #227169: Be careful when creating service thre...
  • Date: Wed, 13 Mar 2013 12:39:20 -0700

changeset bf391d6a6c3c in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/bf391d6a6c3c
description:
        #227169: Be careful when creating service thread and catch potential 
SecurityException.

diffstat:

 
debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteAWTService.java
        |  12 +++-
 
debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteFXService.java
         |   3 +-
 
debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/RemoteServices.java
                       |  23 +++++++++-
 
debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/VisualDebuggerListener.java
               |  13 ++++-
 
debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/actions/TakeScreenshotActionProvider.java
 |   2 +-
 5 files changed, 45 insertions(+), 8 deletions(-)

diffs (141 lines):

diff --git 
a/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteAWTService.java
 
b/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteAWTService.java
--- 
a/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteAWTService.java
+++ 
b/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteAWTService.java
@@ -80,14 +80,20 @@
     public RemoteAWTService() {
     }
     
-    static void startAccessLoop() {
+    static boolean startAccessLoop() {
         if (!awtAccessLoop) {
-            awtAccessLoop = true;
-            Thread loop = new Thread(new AWTAccessLoop(), 
AWTAccessThreadName);
+            Thread loop;
+            try {
+                loop = new Thread(new AWTAccessLoop(), AWTAccessThreadName);
             loop.setDaemon(true);
             loop.setPriority(Thread.MIN_PRIORITY);
+            } catch (SecurityException se) {
+                return false;
+            }
+            awtAccessLoop = true;
             loop.start();
         }
+        return true;
     }
     
     static void stopAccessLoop() {
diff --git 
a/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteFXService.java
 
b/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteFXService.java
--- 
a/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteFXService.java
+++ 
b/debugger.jpda.visual/remotesrc/org/netbeans/modules/debugger/jpda/visual/remote/RemoteFXService.java
@@ -94,10 +94,11 @@
     
     final private static Thread accessThread = new Thread(new 
FXAccessLoop(), "FX Access Thread (Visual Debugger)"); // NOI18N
     
-    public static void startAccessLoop() {
+    public static boolean startAccessLoop() {
         accessThread.setDaemon(true);
         accessThread.setPriority(Thread.MIN_PRIORITY);
         accessThread.start();
+        return true;
     }
     
     private static void access() {
diff --git 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/RemoteServices.java
 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/RemoteServices.java
--- 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/RemoteServices.java
+++ 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/RemoteServices.java
@@ -129,6 +129,7 @@
     private static final String REMOTE_CLASSES_ZIPFILE = 
"/org/netbeans/modules/debugger/jpda/visual/resources/debugger-remote.zip";
     
     private static final Map<JPDADebugger, ClassObjectReference> 
remoteServiceClasses = new WeakHashMap<JPDADebugger, ClassObjectReference>();
+    private static final Map<JPDADebugger, Boolean> remoteServiceAccess = 
new WeakHashMap<JPDADebugger, Boolean>();
     
     private static final RequestProcessor AUTORESUME_AFTER_SUSPEND_RP = new 
RequestProcessor("Autoresume after suspend", 1);
     
@@ -142,7 +143,7 @@
         }
     }
 
-    private static void fireServiceClass(JPDADebuggerImpl debugger) {
+    private static void fireServiceClass(JPDADebugger debugger) {
         PropertyChangeEvent pche = new 
PropertyChangeEvent(RemoteServices.class, "serviceClass", null, debugger);
         PropertyChangeListener[] listeners;
         synchronized (serviceListeners) {
@@ -1014,6 +1015,26 @@
         }
     }
     
+    static void setAccessLoopStarted(JPDADebugger debugger, boolean success) 
{
+        synchronized (remoteServiceAccess) {
+            remoteServiceAccess.put(debugger, success);
+        }
+        fireServiceClass(debugger);
+    }
+    
+    public static boolean hasServiceAccess(JPDADebugger debugger) {
+        ClassObjectReference serviceClass = getServiceClass(debugger);
+        if (serviceClass != null) {
+            Boolean has;
+            synchronized (remoteServiceAccess) {
+                has = remoteServiceAccess.get(debugger);
+            }
+            return has != null && has.booleanValue();
+        } else {
+            return false;
+        }
+    }
+    
     public static ClassObjectReference getServiceClass(JPDADebugger 
debugger) {
         synchronized (remoteServiceClasses) {
             return remoteServiceClasses.get(debugger);
diff --git 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/VisualDebuggerListener.java
 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/VisualDebuggerListener.java
--- 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/VisualDebuggerListener.java
+++ 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/VisualDebuggerListener.java
@@ -51,6 +51,7 @@
 import com.sun.jdi.InvocationException;
 import com.sun.jdi.Method;
 import com.sun.jdi.ObjectReference;
+import com.sun.jdi.PrimitiveValue;
 import com.sun.jdi.ReferenceType;
 import com.sun.jdi.StringReference;
 import com.sun.jdi.ThreadReference;
@@ -92,6 +93,7 @@
 import org.netbeans.modules.debugger.jpda.jdi.InternalExceptionWrapper;
 import 
org.netbeans.modules.debugger.jpda.jdi.ObjectCollectedExceptionWrapper;
 import org.netbeans.modules.debugger.jpda.jdi.ObjectReferenceWrapper;
+import org.netbeans.modules.debugger.jpda.jdi.PrimitiveValueWrapper;
 import org.netbeans.modules.debugger.jpda.jdi.ReferenceTypeWrapper;
 import 
org.netbeans.modules.debugger.jpda.jdi.UnsupportedOperationExceptionWrapper;
 import org.netbeans.modules.debugger.jpda.jdi.VMDisconnectedExceptionWrapper;
@@ -288,10 +290,17 @@
             ClassType serviceClass = (ClassType) 
ClassObjectReferenceWrapper.reflectedType(cor);//RemoteServices.getClass(vm, 
"org.netbeans.modules.debugger.jpda.visual.remote.RemoteService");
 
             InvocationExceptionTranslated iextr = null;
-            Method startMethod = 
ClassTypeWrapper.concreteMethodByName(serviceClass, "startAccessLoop", "()V");
+            Method startMethod = 
ClassTypeWrapper.concreteMethodByName(serviceClass, "startAccessLoop", "()Z");
             try {
                 t.notifyMethodInvoking();
-                ClassTypeWrapper.invokeMethod(serviceClass, tr, startMethod, 
Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
+                Value ret = ClassTypeWrapper.invokeMethod(serviceClass, tr, 
startMethod, Collections.EMPTY_LIST, ObjectReference.INVOKE_SINGLE_THREADED);
+                if (ret instanceof PrimitiveValue) {
+                    boolean success = 
PrimitiveValueWrapper.booleanValue((PrimitiveValue) ret);
+                    RemoteServices.setAccessLoopStarted(t.getDebugger(), 
success);
+                    if (!success) {
+                        return ;
+                    }
+                }
                 boolean trackComponentChanges = 
properties.getBoolean(PROPERTIES_TCC, true);
                 isTrackComponentChanges = trackComponentChanges;
                 if (trackComponentChanges && 
RemoteAWTScreenshot.FAST_SNAPSHOT_RETRIEVAL) {
diff --git 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/actions/TakeScreenshotActionProvider.java
 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/actions/TakeScreenshotActionProvider.java
--- 
a/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/actions/TakeScreenshotActionProvider.java
+++ 
b/debugger.jpda.visual/src/org/netbeans/modules/debugger/jpda/visual/actions/TakeScreenshotActionProvider.java
@@ -180,7 +180,7 @@
                 @Override
                 public void propertyChange(PropertyChangeEvent evt) {
                     //firePropertyChange("enabled", null, null);
-                    setEnabled(ScreenshotUIManager.ACTION_TAKE_SCREENSHOT, 
RemoteServices.getServiceClass(debugger) != null);
+                    setEnabled(ScreenshotUIManager.ACTION_TAKE_SCREENSHOT, 
RemoteServices.hasServiceAccess(debugger));
                 }
             };
         

[hg] main-silver: #227169: Be careful when creating service thre...

mentlicher 03/13/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close