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

NullPointerException with DoubleLiteral #755

Closed
msteinbeck opened this issue Jul 22, 2016 · 1 comment
Closed

NullPointerException with DoubleLiteral #755

msteinbeck opened this issue Jul 22, 2016 · 1 comment

Comments

@msteinbeck
Copy link
Contributor

Hi,

I get a NullPointerException when creating a spoon model for the following code:

import java.util.HashMap;
import java.util.Map;

public class DoubleLiteralBug {

    public static void main(final String[] args) {
        Map<String, UknownClass> map = new HashMap<>();

        map.forEach((key, value) -> {
            double d = 1d;
        });
    }
}

The model is created as follows:
(with projectPath being the path to the DoubleLiteralBug.java file)

Launcher runLaunch = new Launcher();
runLaunch.getEnvironment().setNoClasspath(true);
runLaunch.addInputResource(projectPath);
runLaunch.buildModel();

I noticed that the error can be removed by either replacing UknownClass with a class available in classpath, or by moving double d = 1d; out of the forEach lambda.

msteinbeck pushed a commit to msteinbeck/spoon that referenced this issue Jul 22, 2016
In some cases (an example is given in INRIA#755) Literal#constant may
be `null` and, thus, causes a NullPointerException when calling
`localDeclaration.initialization.traverse(this, scope);`. This
patch fixes the issue by resolving Literal#constant if required.
@msteinbeck
Copy link
Contributor Author

A potential fix is given in #758.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant