matthiasblaesing closed pull request #313: [NETBEANS-194] Don't return NULL 
from ShellProjectUtils#launchVMOptions and compilerPathOptions
URL: https://github.com/apache/incubator-netbeans/pull/313
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/jshell.support/src/org/netbeans/modules/jshell/env/JShellEnvironment.java 
b/jshell.support/src/org/netbeans/modules/jshell/env/JShellEnvironment.java
index d1d124cf2..2a3bc1532 100644
--- a/jshell.support/src/org/netbeans/modules/jshell/env/JShellEnvironment.java
+++ b/jshell.support/src/org/netbeans/modules/jshell/env/JShellEnvironment.java
@@ -20,7 +20,6 @@
 
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
 import java.io.File;
 import java.io.FilterReader;
 import java.io.IOException;
@@ -29,9 +28,7 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Set;
 import javax.swing.text.Document;
 import jdk.jshell.JShell;
 import jdk.jshell.spi.ExecutionControlProvider;
@@ -41,20 +38,16 @@
 import org.netbeans.api.java.queries.SourceLevelQuery.Result;
 import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.ClasspathInfo.PathKind;
-import org.netbeans.api.java.source.SourceUtils;
-import org.netbeans.api.project.FileOwnerQuery;
 import org.netbeans.api.project.Project;
 import org.netbeans.modules.jshell.model.ConsoleEvent;
 import org.netbeans.modules.jshell.model.ConsoleListener;
 import org.netbeans.modules.jshell.project.ShellProjectUtils;
 import org.netbeans.modules.jshell.support.ShellSession;
-import static org.netbeans.modules.jshell.tool.JShellLauncher.quote;
 import org.netbeans.spi.java.classpath.ClassPathFactory;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.cookies.EditorCookie;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
-import org.openide.filesystems.URLMapper;
 import org.openide.loaders.DataObject;
 import org.openide.modules.SpecificationVersion;
 import org.openide.util.Exceptions;
@@ -718,7 +711,7 @@ public JShell getShell() {
         return s == null ? null : s.getShell();
     }
     
-    class ShellL implements PropertyChangeListener {
+    private class ShellL implements PropertyChangeListener {
 
         @Override
         public void propertyChange(PropertyChangeEvent evt) {
diff --git 
a/jshell.support/src/org/netbeans/modules/jshell/j2se/JShellStartupExtender.java
 
b/jshell.support/src/org/netbeans/modules/jshell/j2se/JShellStartupExtender.java
index a5967f93c..011723175 100644
--- 
a/jshell.support/src/org/netbeans/modules/jshell/j2se/JShellStartupExtender.java
+++ 
b/jshell.support/src/org/netbeans/modules/jshell/j2se/JShellStartupExtender.java
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -81,12 +80,10 @@
         List<String> args = ShellProjectUtils.quoteCmdArgs(
                 ShellLaunchManager.buildLocalJVMAgentArgs(platform, agent, 
prjEval.evaluator()::getProperty)
         );
+
+        args.addAll(ShellProjectUtils.launchVMOptions(p));
+
         LOG.log(Level.FINE, "Final args: {0}", args);
-        
-        List<String> shellArgs = ShellProjectUtils.launchVMOptions(p);
-        if (shellArgs != null) {
-            args.addAll(shellArgs);
-        }
         return args;
     }
 }
diff --git 
a/jshell.support/src/org/netbeans/modules/jshell/maven/MavenShellLauncher.java 
b/jshell.support/src/org/netbeans/modules/jshell/maven/MavenShellLauncher.java
index 05b9c3ab5..9501dd05a 100644
--- 
a/jshell.support/src/org/netbeans/modules/jshell/maven/MavenShellLauncher.java
+++ 
b/jshell.support/src/org/netbeans/modules/jshell/maven/MavenShellLauncher.java
@@ -102,10 +102,7 @@ public boolean checkRunConfig(RunConfig config, 
ExecutionContext con) {
                 config.getProperties()::get
         );
         String agentString = args.get(args.size() -1);
-        List<String> vmArgs = ShellProjectUtils.launchVMOptions(project);
-        if (vmArgs != null) {
-            args.addAll(vmArgs);
-        }
+        args.addAll(ShellProjectUtils.launchVMOptions(project));
         String execArgs = config.getProperties().get(PROPERTY_EXEC_ARGS);
         if (execArgs != null) {
             StringBuilder sb = new StringBuilder();
diff --git 
a/jshell.support/src/org/netbeans/modules/jshell/project/ShellProjectUtils.java 
b/jshell.support/src/org/netbeans/modules/jshell/project/ShellProjectUtils.java
index 7108250de..eddf05e9e 100644
--- 
a/jshell.support/src/org/netbeans/modules/jshell/project/ShellProjectUtils.java
+++ 
b/jshell.support/src/org/netbeans/modules/jshell/project/ShellProjectUtils.java
@@ -18,28 +18,18 @@
  */
 package org.netbeans.modules.jshell.project;
 
-import com.sun.source.tree.DirectiveTree;
-import com.sun.source.tree.ModuleTree;
-import com.sun.source.tree.RequiresTree;
-import com.sun.source.tree.Tree;
-import com.sun.source.tree.Tree.Kind;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
-import javax.lang.model.element.ModuleElement;
-import javax.lang.model.element.ModuleElement.DirectiveKind;
-import javax.lang.model.element.ModuleElement.RequiresDirective;
+import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.api.debugger.Session;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.classpath.JavaClassPathConstants;
@@ -53,26 +43,16 @@
 import org.netbeans.api.java.source.ClassIndex.SearchScope;
 import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.ClasspathInfo.PathKind;
-import org.netbeans.api.java.source.CompilationInfo;
-import org.netbeans.api.java.source.JavaSource;
 import org.netbeans.api.java.source.SourceUtils;
 import org.netbeans.api.project.Project;
 import org.netbeans.api.project.ProjectManager;
 import org.netbeans.api.project.ProjectUtils;
 import org.netbeans.api.project.SourceGroup;
-import org.netbeans.api.project.Sources;
 import org.netbeans.modules.java.api.common.project.ProjectProperties;
 import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator;
-import org.netbeans.modules.java.source.parsing.FileObjects;
 import org.netbeans.modules.jshell.launch.PropertyNames;
 import org.netbeans.modules.maven.api.execute.RunUtils;
-import org.netbeans.modules.parsing.api.ParserManager;
-import org.netbeans.modules.parsing.api.ResultIterator;
-import org.netbeans.modules.parsing.api.Source;
-import org.netbeans.modules.parsing.api.UserTask;
-import org.netbeans.modules.parsing.spi.ParseException;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
-import org.netbeans.spi.project.AuxiliaryProperties;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.URLMapper;
@@ -327,7 +307,7 @@ public static ClassPath projecRuntimeClassPath(Project 
project) {
             if (!isNormalRoot(sg)) {
                 continue;
             }
-            ClassPath del = null; 
+            ClassPath del; 
             if (modular) {
                 del = ClassPath.getClassPath(sg.getRootFolder(), 
JavaClassPathConstants.MODULE_EXECUTE_CLASS_PATH);
             } else {
@@ -339,7 +319,8 @@ public static ClassPath projecRuntimeClassPath(Project 
project) {
         }
         return ClassPathSupport.createProxyClassPath(delegates.toArray(new 
ClassPath[delegates.size()]));
     }
-    
+
+    @NonNull
     public static List<String[]> compilerPathOptions(Project project) {
         List<String[]> result = new ArrayList<>();
         List<String> exportMods = new ArrayList<>(
@@ -348,9 +329,8 @@ public static ClassPath projecRuntimeClassPath(Project 
project) {
         );
         boolean modular = isModularProject(project, false);
         if (exportMods.isEmpty() || !modular) {
-            return null;
+            return result;
         }
-        List<String> addReads = new ArrayList<>();
         Collections.sort(exportMods);
         result.add(new String[] { "--add-modules", String.join(",", 
exportMods) });
         
@@ -366,17 +346,19 @@ public static ClassPath projecRuntimeClassPath(Project 
project) {
         }
         return result;
     }
-    
+
+    @NonNull
     public static List<String> launchVMOptions(Project project) {
         List<String> exportMods = new ArrayList<>(
                 ShellProjectUtils.findProjectImportedModules(project, 
                     ShellProjectUtils.findProjectModules(project, null))
         );
+        
+        List<String> addReads = new ArrayList<>();
         boolean modular = isModularProject(project, false);
         if (exportMods.isEmpty() || !modular) {
-            return null;
+            return addReads;
         }
-        List<String> addReads = new ArrayList<>();
         exportMods.add("jdk.jshell"); // NOI18N
         Collections.sort(exportMods);
         addReads.add("--add-modules"); // NOI18N
diff --git 
a/jshell.support/src/org/netbeans/modules/jshell/support/ShellSession.java 
b/jshell.support/src/org/netbeans/modules/jshell/support/ShellSession.java
index cf8200ab8..bc2ec7407 100644
--- a/jshell.support/src/org/netbeans/modules/jshell/support/ShellSession.java
+++ b/jshell.support/src/org/netbeans/modules/jshell/support/ShellSession.java
@@ -37,8 +37,6 @@
 import java.io.Writer;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
@@ -68,7 +66,6 @@
 import javax.swing.text.Document;
 import javax.swing.text.Position;
 import javax.swing.text.StyledDocument;
-import javax.tools.JavaFileManager;
 import javax.tools.StandardJavaFileManager;
 import org.netbeans.lib.nbjshell.RemoteJShellService;
 import jdk.jshell.JShell;
@@ -87,8 +84,6 @@
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.classpath.GlobalPathRegistry;
 import org.netbeans.api.java.platform.JavaPlatform;
-import org.netbeans.api.java.queries.SourceLevelQuery;
-import org.netbeans.api.java.queries.SourceLevelQuery.Result;
 import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.ClasspathInfo.PathKind;
 import org.netbeans.api.project.Project;
@@ -146,7 +141,7 @@
  * @author sdedic
  */
 public class ShellSession  {
-    private static Logger LOG = Logger.getLogger(ShellSession.class.getName());
+    private static final Logger LOG = 
Logger.getLogger(ShellSession.class.getName());
     
     public static final String PROP_ACTIVE = "active";
     public static final String PROP_ENGINE = "active";
@@ -614,6 +609,7 @@ public Launcher(ExecutionControlProvider execEnv) throws 
IOException {
                 execEnv);
         }
 
+        @Override
         protected List<String>  historyItems() {
             return ShellSession.this.historyItems().stream().map((i) -> 
i.getContents()).collect(Collectors.toList());
         }
@@ -720,7 +716,8 @@ protected NbExecutionControl 
execControlCreated(NbExecutionControl ctrl) {
                 if (kind == PathKind.OUTPUT) {
                     continue;
                 }
-                sb.append(kind + ": ");
+                sb.append(kind);
+                sb.append(": ");
                 ClassPath cp;
                 try {
                     cp = cpI.getClassPath(kind);
@@ -734,7 +731,9 @@ protected NbExecutionControl 
execControlCreated(NbExecutionControl ctrl) {
                 }
                 sb.append("\n");
                 for (ClassPath.Entry e : cp.entries()) {
-                    sb.append("\t" + e.getURL() + "\n");
+                    sb.append("\t");
+                    sb.append(e.getURL());
+                    sb.append("\n");
                 }
                 sb.append("---------------\n");
                 LOG.log(Level.FINEST, sb.toString());
@@ -812,7 +811,7 @@ private synchronized Launcher initShellLauncher() throws 
IOException {
         try {
             launcher = new Launcher(env.createExecutionEnv());
         } catch (IOException | RuntimeException | Error e) {
-            e.printStackTrace();
+            LOG.log(Level.INFO, null, e);
         }
         return launcher;
     }
@@ -848,7 +847,7 @@ private void initJShell() {
         }
     }
     
-    private ShellAccessBridge bridgeImpl = new ShellAccessBridge() {
+    private final ShellAccessBridge bridgeImpl = new ShellAccessBridge() {
         @Override
         public <T> T execute(Callable<T> xcode) throws Exception {
             if (fileman == null || evaluator.isRequestProcessorThread()) {
@@ -988,7 +987,7 @@ private void writeToShellDocument(String text) {
         model.writeToShellDocument(text);
     }
     
-    private Set<Snippet>    excludedSnippets = new HashSet<>();
+    private final Set<Snippet> excludedSnippets = new HashSet<>();
     
     private String getClasspathAsString(PathKind pk) {
         return addRoots("", getClasspathInfo().getClassPath(pk));
@@ -1060,11 +1059,7 @@ private void saveInputSections(ShellHistory history) {
     }
     
     private void closedDelayed() {
-        FORCE_CLOSE_RP.post(new Runnable() {
-            public void run() {
-                closed();
-            }
-        }, 300);
+        FORCE_CLOSE_RP.post(() -> { closed(); }, 300);
     }
 
     private synchronized void init(ShellSession prev) {
@@ -1311,7 +1306,7 @@ private void doExecuteCommands(final String cmd) {
         private final String          cmd;
         private final ConsoleSection  exec;
         
-        private List<String>    toExec = new ArrayList<>();
+        private final List<String>    toExec = new ArrayList<>();
         private boolean         erroneous;
         private int             execOffset;
 
@@ -1415,7 +1410,7 @@ void execute() {
                     reportErrorMessage(ex);
                     reportShellMessage(Bundle.MSG_ErrorExecutingCommand());
                 } finally {
-                    if (sub != null) {
+                    if (sh != null && sub != null) {
                         sh.unsubscribe(sub);
                     }
                     ensureInputSectionAvailable();
@@ -1461,10 +1456,6 @@ public Task closeSession() {
         return detach();
     }
     
-    interface Processor {
-        public void handle(String data);
-    }
-    
     public ConsoleModel getModel() {
         return model;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to