Preparing a possible 12.2 release, and improving compatibility with JDK 16

diff --git a/.travis.yml b/.travis.yml
index 32d137f..e46bd23 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,8 +24,8 @@
 jdk:
   - openjdk11
 before_script:
-  - wget 'https://archive.apache.org/dist/netbeans/netbeans/11.3/netbeans-11.3-bin.zip' -O /tmp/netbeans-11.3-bin.zip
-  - (cd $HOME; unzip /tmp/netbeans-11.3-bin.zip)
+  - wget 'https://archive.apache.org/dist/netbeans/netbeans/12.2/netbeans-12.2-bin.zip' -O /tmp/netbeans-12.2-bin.zip
+  - (cd $HOME; unzip /tmp/netbeans-12.2-bin.zip)
   - unset _JAVA_OPTIONS
 script:
   - export JDK11=$JAVA_HOME
diff --git a/cmdline/README.md b/cmdline/README.md
index 146db79..c5ede07 100644
--- a/cmdline/README.md
+++ b/cmdline/README.md
@@ -27,7 +27,7 @@
 
 #### To Build
 
-* Apache NetBeans 12.0
+* Apache NetBeans 12.2
 * JDK 8 and JDK 11
 * bash
 * Apache ant 1.9.9 or above
@@ -42,7 +42,7 @@
 Build using:
 
 ```
-$ ant -DNETBEANS_PLATFORM=<path-to-NetBeans-12.0> -DJDK11=<path-to-JDK-11> build-and-test
+$ ant -DNETBEANS_PLATFORM=<path-to-NetBeans-12.2> -DJDK11=<path-to-JDK-11> build-and-test
 ```
 
 The built product is in tool/build/jackpot.
diff --git a/cmdline/build.xml b/cmdline/build.xml
index 6358c97..40d1a45 100644
--- a/cmdline/build.xml
+++ b/cmdline/build.xml
@@ -52,7 +52,7 @@
     </target>
 
     <target name="build-and-test">
-        <property name="version" value="12.0" />
+        <property name="version" value="12.2" />
         <condition property="jackpot.root" value="${basedir}" else="${basedir}/..">
             <available file="${basedir}/LICENSE" />
         </condition>
diff --git a/cmdline/lib/nbproject/project.properties b/cmdline/lib/nbproject/project.properties
index 3ff4e3b..20a0642 100644
--- a/cmdline/lib/nbproject/project.properties
+++ b/cmdline/lib/nbproject/project.properties
@@ -17,3 +17,4 @@
 javac.source=1.8
 javac.compilerargs=-Xlint -Xlint:-serial
 spec.version.base=1.16.0
+cp.extra=${tools.jar}
diff --git a/cmdline/lib/src/org/netbeans/modules/jackpot30/cmdline/lib/Utils.java b/cmdline/lib/src/org/netbeans/modules/jackpot30/cmdline/lib/Utils.java
index 36ecc04..ceb220c 100644
--- a/cmdline/lib/src/org/netbeans/modules/jackpot30/cmdline/lib/Utils.java
+++ b/cmdline/lib/src/org/netbeans/modules/jackpot30/cmdline/lib/Utils.java
@@ -18,18 +18,29 @@
  */
 package org.netbeans.modules.jackpot30.cmdline.lib;
 
+import com.sun.source.util.JavacTask;
 import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.regex.Pattern;
+import javax.tools.ForwardingJavaFileManager;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileManager.Location;
+import javax.tools.ToolProvider;
 import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.modules.java.hints.providers.spi.HintDescription;
@@ -157,4 +168,25 @@
             jrtRoot :
             modules;
     }
+
+    public static void addExports() {
+        class CurrentClassLoaderFM extends ForwardingJavaFileManager<JavaFileManager> {
+            public CurrentClassLoaderFM(JavaFileManager delegate) {
+                super(delegate);
+            }
+            @Override
+            public ClassLoader getClassLoader(Location location) {
+                return Utils.class.getClassLoader();
+            }
+        }
+        JavaCompiler compilerTool = ToolProvider.getSystemJavaCompiler();
+        try (CurrentClassLoaderFM fm = new CurrentClassLoaderFM(compilerTool.getStandardFileManager(d -> {}, null, null))) {
+            PrintWriter nullWriter = new PrintWriter(new StringWriter());
+            //using JavacTask.analyze instead of CompilationTask.call to avoid closing the current ClassLoader:
+            ((JavacTask) compilerTool.getTask(nullWriter, fm, d -> {}, Arrays.asList("-proc:none", "-XDaccessInternalAPI"), Arrays.asList("java.lang.Object"), null)).analyze();
+        } catch (IOException ex) {
+            //ignore...
+            ex.printStackTrace();
+        }
+    }
 }
diff --git a/cmdline/maven/pom.xml b/cmdline/maven/pom.xml
index d1c58eb..eaba73f 100644
--- a/cmdline/maven/pom.xml
+++ b/cmdline/maven/pom.xml
@@ -21,7 +21,7 @@
 
   <groupId>org.apache.netbeans.modules.jackpot30</groupId>
   <artifactId>jackpot30-maven-plugin</artifactId>
-  <version>12.0</version>
+  <version>12.2</version>
   <packaging>maven-plugin</packaging>
 
   <name>Jackpot 3.0 Command Line Tool Maven Bridge</name>
diff --git a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
index cb46dce..415ab66 100644
--- a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
+++ b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
@@ -67,7 +67,7 @@
 
         Process p = Runtime.getRuntime().exec(new String[] {
             maven,
-            "-Djackpot.plugin.version=12.0",
+            "-Djackpot.plugin.version=12.2",
             "-q",
             "jackpot30:analyze"
         }, null, testDir);
diff --git a/cmdline/maven/tests/sl-17/src/main/java/test/App.java b/cmdline/maven/tests/sl-17/src/main/java/test/App.java
index 80b18f6..37f42dc 100644
--- a/cmdline/maven/tests/sl-17/src/main/java/test/App.java
+++ b/cmdline/maven/tests/sl-17/src/main/java/test/App.java
@@ -22,5 +22,6 @@
 
     public static void main( String[] args ) {
         Runnable r = new Runnable() { public void run() { } };
+        r.run();
     }
 }
diff --git a/cmdline/maven/tests/sl-18/src/main/java/test/App.java b/cmdline/maven/tests/sl-18/src/main/java/test/App.java
index 80b18f6..37f42dc 100644
--- a/cmdline/maven/tests/sl-18/src/main/java/test/App.java
+++ b/cmdline/maven/tests/sl-18/src/main/java/test/App.java
@@ -22,5 +22,6 @@
 
     public static void main( String[] args ) {
         Runnable r = new Runnable() { public void run() { } };
+        r.run();
     }
 }
diff --git a/cmdline/tool/scripts/pom.xml b/cmdline/tool/scripts/pom.xml
index 2fea196..d5a14f7 100644
--- a/cmdline/tool/scripts/pom.xml
+++ b/cmdline/tool/scripts/pom.xml
@@ -21,7 +21,7 @@
 
   <groupId>org.apache.netbeans.modules.jackpot30</groupId>
   <artifactId>jackpot30-maven-plugin</artifactId>
-  <version>12.0</version>
+  <version>12.2</version>
   <packaging>maven-plugin</packaging>
 
   <name>Jackpot 3.0 Command Line Tool</name>
diff --git a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
index 62a64af..96d9235 100644
--- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
+++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
@@ -65,6 +65,7 @@
 import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
+import org.netbeans.api.actions.Savable;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.source.CompilationController;
 import org.netbeans.api.java.source.ModificationResult;
@@ -107,7 +108,6 @@
 import org.netbeans.spi.java.hints.Hint.Kind;
 import org.netbeans.spi.java.hints.HintContext;
 import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
-import org.openide.cookies.EditorCookie;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.text.PositionRef;
@@ -143,6 +143,9 @@
             System.err.println("Error: no suitable javac found, please run on JDK 11+.");
             return 1;
         }
+
+        Utils.addExports();
+
         System.setProperty("netbeans.user", "/tmp/tmp-foo");
         System.setProperty("SourcePath.no.source.filter", "true");
 
@@ -884,6 +887,13 @@
         } else {
             for (ModificationResult mr : diffs) {
                 mr.commit();
+                //ensure all modified files are saved:
+                for (FileObject file : mr.getModifiedFileObjects()) {
+                    Savable sc = file.getLookup().lookup(Savable.class);
+                    if (sc != null) {
+                        sc.save();
+                    }
+                }
             }
         }
     }
diff --git a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
index 0014e97..0826581 100644
--- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
+++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
@@ -27,13 +27,10 @@
 import com.sun.source.util.TreePath;
 import com.sun.source.util.TreePathScanner;
 import com.sun.source.util.Trees;
-import com.sun.tools.javac.comp.Resolve;
-import com.sun.tools.javac.util.Context;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
@@ -85,7 +82,6 @@
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.filesystems.URLMapper;
-import org.openide.util.Exceptions;
 import org.openide.util.Lookup;
 
 /**
@@ -138,15 +134,16 @@
     }
 
     private void runHints() {
+        Utils.addExports();
+
         Trees trees = Trees.instance(processingEnv);
         Level originalLoggerLevel = TOP_LOGGER.getLevel();
         Path toDelete = null;
         try {
             TOP_LOGGER.setLevel(Level.OFF);
             System.setProperty("RepositoryUpdate.increasedLogLevel", "OFF");
-            Field contextField = processingEnv.getClass().getDeclaredField("context");
-            contextField.setAccessible(true);
-            Object context = contextField.get(processingEnv);
+            Method getContext = processingEnv.getClass().getDeclaredMethod("getContext");
+            Object context = getContext.invoke(processingEnv);
             Method get = context.getClass().getDeclaredMethod("get", Class.class);
             JavaFileManager fileManager = (JavaFileManager) get.invoke(context, JavaFileManager.class);
 
@@ -240,7 +237,7 @@
                     }
                 }
             }, true);
-        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | IOException ex) {
+        } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | IOException ex) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Unexpected exception: " + ex.getMessage());
             Logger.getLogger(ProcessorImpl.class.getName()).log(Level.SEVERE, null, ex);
         } finally {
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolProcessorTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolProcessorTest.java
index 49f55ee..6b783c2 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolProcessorTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolProcessorTest.java
@@ -89,7 +89,12 @@
         @Override
         public void run() {
             try {
-                FileUtil.copy(ins, out);
+                int read;
+
+                while ((read = ins.read()) != (-1)) {
+                    out.write(read);
+                    System.out.write(read);
+                }
             } catch (IOException ex) {
                 Exceptions.printStackTrace(ex);
             } finally {
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
index 7595365..2d8bd6b 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
@@ -26,7 +26,6 @@
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.Writer;
-import java.lang.annotation.RetentionPolicy;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -251,26 +250,22 @@
     }
 
     public void testConfigurationFileCmdLineOverride() throws Exception {
-        String golden =
+        String code =
             "package test;\n" +
             "public class Test {\n" +
-            "    private void test(java.util.Collection c) {\n" +
+            "    public boolean test(java.util.Collection c) {\n" +
             "        boolean b = c.size() == 0;\n" +
+            "        return b;\n" +
             "    }\n" +
             "}\n";
 
-        doRunCompiler(golden,
+        doRunCompiler(code,
                       "${workdir}/src/test/Test.java:4: warning: [Usage_of_size_equals_0] Usage of .size() == 0 can be replaced with .isEmpty()\n" +
                       "        boolean b = c.size() == 0;\n" +
                       "                    ^\n",
                       null,
                       "src/test/Test.java",
-                      "package test;\n" +
-                      "public class Test {\n" +
-                      "    private void test(java.util.Collection c) {\n" +
-                      "        boolean b = c.size() == 0;\n" +
-                      "    }\n" +
-                      "}\n",
+                      code,
                       "settings.xml",
                       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                       "<!DOCTYPE configuration PUBLIC \"-//NetBeans//DTD Tool Configuration 1.0//EN\" \"http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd\">\n" +
@@ -374,9 +369,10 @@
         String code =
             "package test;\n" +
             "public class Test {\n" +
-            "    private void test(java.util.Collection c) {\n" +
+            "    public boolean test(java.util.Collection c) {\n" +
             "        boolean b1 = c.size() == 0;\n" +
             "        boolean b2 = c.size() <= 0;\n" +
+            "        return b1 || b2;\n" +
             "    }\n" +
             "}\n";
 
@@ -1149,6 +1145,7 @@
             "public class DoRunTests extends DeclarativeHintsTestBase {\n" +
             "\n" +
             "    public static TestSuite suite() {\n" +
+            "        org.netbeans.modules.jackpot30.cmdline.lib.Utils.addExports();\n" + //TODO: should be part of DeclarativeHintsTestBase!
             "        return suite(DoRunTests.class);\n" +
             "    }\n" +
             "\n" +
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImplTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImplTest.java
index 8f16ba4..2079efa 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImplTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImplTest.java
@@ -19,11 +19,8 @@
 package org.netbeans.modules.jackpot30.cmdline;
 
 import com.sun.tools.javac.Main;
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -35,7 +32,6 @@
 import static junit.framework.TestCase.assertEquals;
 import static junit.framework.TestCase.assertTrue;
 import org.netbeans.junit.NbTestCase;
-import org.openide.filesystems.FileUtil;
 
 /**
  *
@@ -59,9 +55,10 @@
                       "src/test/Test.java",
                       "package test;\n" +
                       "public class Test {\n" +
-                      "    private void test(java.util.Collection c) {\n" +
+                      "    public boolean test(java.util.Collection c) {\n" +
                       "        boolean b1 = c.size() == 0;\n" +
                       "\tboolean b2 = c.size() == 0;\n" +
+                      "        return b1 || b2;\n" +
                       "    }\n" +
                       "}\n",
                       null,
@@ -82,9 +79,10 @@
                       "src/test/Test.java",
                       "package test;\n" +
                       "public class Test {\n" +
-                      "    private void test(java.util.Collection c) {\n" +
+                      "    public boolean test(java.util.Collection c) {\n" +
                       "        boolean b1 = c.size() == 0;\n" +
                       "\tboolean b2 = c.size() == 0;\n" +
+                      "        return b1 || b2;\n" +
                       "    }\n" +
                       "}\n",
                       "cfg_hints.xml",
@@ -116,9 +114,10 @@
                       "src/test/Test.java",
                       "package test;\n" +
                       "public class Test {\n" +
-                      "    private void test(Test c) {\n" +
+                      "    public boolean test(Test c) {\n" +
                       "        boolean b1 = c.size() == 0;\n" +
                       "\tboolean b2 = c.size() == 0;\n" +
+                      "        return b1 || b2;\n" +
                       "    }\n" +
                       "    public int size() { return 0; }\n" +
                       "}\n",
@@ -144,9 +143,10 @@
                       "src/test/Test.java",
                       "package test;\n" +
                       "public class Test {\n" +
-                      "    private void test(Test c) {\n" +
+                      "    public boolean test(Test c) {\n" +
                       "        boolean b1 = c.size() == 0;\n" +
                       "\tboolean b2 = c.size() == 0;\n" +
+                      "        return b1 || b2;\n" +
                       "    }\n" +
                       "    public int size() { return 0; }\n" +
                       "}\n",