You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2023/07/04 03:38:54 UTC

[GitHub] [groovy] paulk-asert opened a new pull request, #1910: GROOVY-11118: Partial JEP 445 compatibility

paulk-asert opened a new pull request, #1910:
URL: https://github.com/apache/groovy/pull/1910

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] paulk-asert merged pull request #1910: GROOVY-11118: Partial JEP 445 compatibility

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #1910:
URL: https://github.com/apache/groovy/pull/1910


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] sonatype-lift[bot] commented on a diff in pull request #1910: GROOVY-11118: Partial JEP 445 compatibility

Posted by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #1910:
URL: https://github.com/apache/groovy/pull/1910#discussion_r1251489336


##########
src/main/java/groovy/lang/GroovyShell.java:
##########
@@ -290,36 +293,62 @@ private Object runScriptOrMainOrTestOrRunnable(Class scriptClass, String[] args)
             }
         }
         try {
-            // let's find a main method
-            scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
-            // if that main method exist, invoke it
-            return InvokerHelper.invokeMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
-        } catch (NoSuchMethodException e) {
-            // if it implements Runnable, try to instantiate it
-            if (Runnable.class.isAssignableFrom(scriptClass)) {
-                return runRunnable(scriptClass, args);
+            // let's find a String[] main method
+            Method stringArrayMain = scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
+            // if that main method exists, invoke it
+            if (Modifier.isStatic(stringArrayMain.getModifiers())) {
+                return InvokerHelper.invokeStaticMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
+            } else {
+                Object script = InvokerHelper.invokeNoArgumentsConstructorOf(scriptClass);
+                return InvokerHelper.invokeMethod(script, MAIN_METHOD_NAME, args);
             }
-            GroovyRunnerRegistry runnerRegistry = GroovyRunnerRegistry.getInstance();
-            for (GroovyRunner runner : runnerRegistry) {
-                if (runner.canRun(scriptClass, this.loader)) {
-                    return runner.run(scriptClass, this.loader);
-                }
+        } catch (NoSuchMethodException ignore) { }

Review Comment:
   <picture><img alt="25% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/25/display.svg"></picture>
   
   <b>*[EmptyCatch](https://google.github.io/styleguide/javaguide.html#s6.2-caught-exceptions):</b>*  Caught exceptions should not be ignored
   
   ❗❗ <b>2 similar findings have been found in this PR</b>
   
   <details><summary>🔎 Expand here to view all instances of this finding</summary><br/>
     
     
   <div align=\"center\">
   
   
   | **File Path** | **Line Number** |
   | ------------- | ------------- |
   | src/main/java/groovy/lang/GroovyShell.java | [327](https://github.com/apache/groovy/blob/6155ca2fc135b786e1a97b5b6a89dde181c7dde3/src/main/java/groovy/lang/GroovyShell.java#L327) |
   | src/main/java/groovy/lang/GroovyShell.java | [316](https://github.com/apache/groovy/blob/6155ca2fc135b786e1a97b5b6a89dde181c7dde3/src/main/java/groovy/lang/GroovyShell.java#L316) |
   <p><a href="https://lift.sonatype.com/results/github.com/apache/groovy/01H4FFPMH4A24S68YT2HY8FFP4?t=ErrorProne|EmptyCatch" target="_blank">Visit the Lift Web Console</a> to find more details in your report.</p></div></details>
   
   
   
   ---
   
   <details><summary>â„šī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] sonatype-lift[bot] commented on a diff in pull request #1910: GROOVY-11118: Partial JEP 445 compatibility

Posted by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org>.
sonatype-lift[bot] commented on code in PR #1910:
URL: https://github.com/apache/groovy/pull/1910#discussion_r1251559681


##########
src/main/java/groovy/lang/GroovyShell.java:
##########
@@ -290,36 +293,62 @@ private Object runScriptOrMainOrTestOrRunnable(Class scriptClass, String[] args)
             }
         }
         try {
-            // let's find a main method
-            scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
-            // if that main method exist, invoke it
-            return InvokerHelper.invokeMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
-        } catch (NoSuchMethodException e) {
-            // if it implements Runnable, try to instantiate it
-            if (Runnable.class.isAssignableFrom(scriptClass)) {
-                return runRunnable(scriptClass, args);
+            // let's find a String[] main method
+            Method stringArrayMain = scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
+            // if that main method exists, invoke it
+            if (Modifier.isStatic(stringArrayMain.getModifiers())) {
+                return InvokerHelper.invokeStaticMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
+            } else {
+                Object script = InvokerHelper.invokeNoArgumentsConstructorOf(scriptClass);
+                return InvokerHelper.invokeMethod(script, MAIN_METHOD_NAME, args);
             }
-            GroovyRunnerRegistry runnerRegistry = GroovyRunnerRegistry.getInstance();
-            for (GroovyRunner runner : runnerRegistry) {
-                if (runner.canRun(scriptClass, this.loader)) {
-                    return runner.run(scriptClass, this.loader);
-                }
+        } catch (NoSuchMethodException ignore) { }

Review Comment:
   I've recorded these 3 issues as ignored for this pull request.
   If you change your mind, just comment `@sonatype-lift unignore`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [groovy] paulk-asert commented on a diff in pull request #1910: GROOVY-11118: Partial JEP 445 compatibility

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #1910:
URL: https://github.com/apache/groovy/pull/1910#discussion_r1251559540


##########
src/main/java/groovy/lang/GroovyShell.java:
##########
@@ -290,36 +293,62 @@ private Object runScriptOrMainOrTestOrRunnable(Class scriptClass, String[] args)
             }
         }
         try {
-            // let's find a main method
-            scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
-            // if that main method exist, invoke it
-            return InvokerHelper.invokeMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
-        } catch (NoSuchMethodException e) {
-            // if it implements Runnable, try to instantiate it
-            if (Runnable.class.isAssignableFrom(scriptClass)) {
-                return runRunnable(scriptClass, args);
+            // let's find a String[] main method
+            Method stringArrayMain = scriptClass.getMethod(MAIN_METHOD_NAME, String[].class);
+            // if that main method exists, invoke it
+            if (Modifier.isStatic(stringArrayMain.getModifiers())) {
+                return InvokerHelper.invokeStaticMethod(scriptClass, MAIN_METHOD_NAME, new Object[]{args});
+            } else {
+                Object script = InvokerHelper.invokeNoArgumentsConstructorOf(scriptClass);
+                return InvokerHelper.invokeMethod(script, MAIN_METHOD_NAME, args);
             }
-            GroovyRunnerRegistry runnerRegistry = GroovyRunnerRegistry.getInstance();
-            for (GroovyRunner runner : runnerRegistry) {
-                if (runner.canRun(scriptClass, this.loader)) {
-                    return runner.run(scriptClass, this.loader);
-                }
+        } catch (NoSuchMethodException ignore) { }

Review Comment:
   @sonatype-lift ignore



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org