[ 
https://issues.apache.org/jira/browse/GROOVY-12376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112180#comment-18112180
 ] 

ASF GitHub Bot commented on GROOVY-12376:
-----------------------------------------

paulk-asert commented on code in PR #2899:
URL: https://github.com/apache/groovy/pull/2899#discussion_r3947153190


##########
subprojects/groovy-swing/src/main/groovy/groovy/swing/LookAndFeelHelper.groovy:
##########
@@ -94,7 +94,16 @@ class LookAndFeelHelper {
                     } else if (theme == 'steel') {
                         theme = new DefaultMetalTheme();
                     } else {
-                        theme = Class.forName(theme as 
String).getConstructor().newInstance()
+                        // resolve without initializing, confirm it is a 
MetalTheme before
+                        // constructing it, and prefer the context classloader 
so application
+                        // and @Grab-supplied theme classes resolve; the 
context loader may be
+                        // null, so fall back to this class's loader (the 
pre-existing behaviour)
+                        def loader = Thread.currentThread().contextClassLoader 
?: LookAndFeelHelper.classLoader
+                        def themeClass = Class.forName(theme as String, false, 
loader)
+                        if (!MetalTheme.isAssignableFrom(themeClass)) {
+                            throw new IllegalArgumentException("Metal theme 
class ${themeClass.name} is not a ${MetalTheme.name}")

Review Comment:
   Nice suggestion. Adopted plus I caught no-arg constructor as well. It would 
have a similar confusing message.





> LookAndFeelHelper: detect non-metal classes rather than fail with an obscure 
> error
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-12376
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12376
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to