Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in CompilerConfiguration #1022

Closed
torsten-witte opened this issue Jan 16, 2020 · 0 comments
Closed

NPE in CompilerConfiguration #1022

torsten-witte opened this issue Jan 16, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@torsten-witte
Copy link

The following code results in a NullPointerException:

ClassLoader classLoader = ...
String url = ...
GroovyScriptEngine engine = new GroovyScriptEngine(url, classLoader);

Here is the stack trace:

java.lang.NullPointerException
	at java.util.Collections$UnmodifiableMap.<init>(Unknown Source)
	at java.util.Collections.unmodifiableMap(Unknown Source)
	at org.codehaus.groovy.control.CompilerConfiguration$1.getJointCompilationOptions(CompilerConfiguration.java:147)
	at org.codehaus.groovy.control.CompilerConfiguration.<init>(CompilerConfiguration.java:481)
	at groovy.util.GroovyScriptEngine.<init>(GroovyScriptEngine.java:96)
	at groovy.util.GroovyScriptEngine.<init>(GroovyScriptEngine.java:495)
	at groovy.util.GroovyScriptEngine.<init>(GroovyScriptEngine.java:503)

The problem is that CompilerConfiguration.DEFAULT.getJointCompilationOptions() wants to create an unmodifiable map with null (jointCompilationOptions is always null at this point).
The error is included since commit b03ff24c8f43088b6edadb1adcf17f7a945d6563.

public class CompilerConfiguration {
    ...
    public static final CompilerConfiguration DEFAULT = new CompilerConfiguration() {
        ...
        @Override
        public Map<String, Object> getJointCompilationOptions() {
                return Collections.unmodifiableMap(super.getJointCompilationOptions());  // <------- NullPointerException
        }
        ...
    }

    /**
     * options for joint compilation (null by default == no joint compilation)
     */
    private Map<String, Object> jointCompilationOptions;

    public CompilerConfiguration(CompilerConfiguration configuration) {
        ...
        Map<String, Object> jointCompilationOptions = configuration.getJointCompilationOptions();
        if (jointCompilationOptions != null) {
            jointCompilationOptions = new HashMap<String, Object>(jointCompilationOptions);
        }
       ...
    }

    public Map<String, Object> getJointCompilationOptions() {
        return jointCompilationOptions;
    }
    ...
}

Here is an easier way to reproduce:

CompilerConfiguration defaultConfig = CompilerConfiguration.DEFAULT;
System.out.println("JointCompilationOptions: " + defaultConfig.getJointCompilationOptions());
@eric-milles eric-milles self-assigned this Jan 16, 2020
@eric-milles eric-milles added this to the v3.7.0 milestone Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants