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.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]