This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 079b677  Ensure Java default imports will be included
079b677 is described below

commit 079b677acd8fd24607e4ed395d60833f9f79ba72
Author: Daniel Sun <sun...@apache.org>
AuthorDate: Sat May 30 23:27:56 2020 +0800

    Ensure Java default imports will be included
---
 .../org/codehaus/groovy/vmplugin/v9/Java9.java     | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java 
b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 05f90ba..9249449 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -94,17 +94,19 @@ public class Java9 extends Java8 {
 
         Map<String, Set<String>> result = new LinkedHashMap<>(2048);
         try (GroovyClassLoader gcl = new 
GroovyClassLoader(this.getClass().getClassLoader())) {
-            URI gsLocation = 
DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
-            result.putAll(doFindClasses(gsLocation, "groovy", groovyPns));
-
-            // in production environment, groovy-core classes, e.g. 
`GroovySystem`(java class) and `GrapeIvy`(groovy class) are all packaged in the 
groovy-core jar file,
-            // but in Groovy development environment, groovy-core classes are 
distributed in different directories
-            URI giLocation = 
DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.grape.GrapeIvy")).toURI();
-            if (!gsLocation.equals(giLocation)) {
-                result.putAll(doFindClasses(giLocation, "groovy", groovyPns));
+            try {
+                URI gsLocation = 
DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.lang.GroovySystem")).toURI();
+                result.putAll(doFindClasses(gsLocation, "groovy", groovyPns));
+
+                // in production environment, groovy-core classes, e.g. 
`GroovySystem`(java class) and `GrapeIvy`(groovy class) are all packaged in the 
groovy-core jar file,
+                // but in Groovy development environment, groovy-core classes 
are distributed in different directories
+                URI giLocation = 
DefaultGroovyMethods.getLocation(gcl.loadClass("groovy.grape.GrapeIvy")).toURI();
+                if (!gsLocation.equals(giLocation)) {
+                    result.putAll(doFindClasses(giLocation, "groovy", 
groovyPns));
+                }
+            } finally {
+                
result.putAll(doFindClasses(URI.create("jrt:/modules/java.base/"), "java", 
javaPns));
             }
-
-            result.putAll(doFindClasses(URI.create("jrt:/modules/java.base/"), 
"java", javaPns));
         } catch (Exception ignore) {
             if (LOGGER.isLoggable(Level.FINEST)) {
                 LOGGER.finest("[WARNING] Failed to find default imported 
classes:\n" + DefaultGroovyMethods.asString(ignore));

Reply via email to