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

ParentNotInitializedException when using Java 14 switch expressions with cases which have multiple values #3680

Closed
davidog23 opened this issue Nov 8, 2020 · 1 comment
Assignees
Labels

Comments

@davidog23
Copy link

spoon-core version: 8.3.0
Code to reproduce the bug:

import spoon.Launcher;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;

public class A {
    public static void main(String[] args) {
        CtClass l = Launcher.parseClass("class A { { int x = switch(1) { case 1, 3 -> 0; default -> 1}; } }");
        for (CtElement a : l.asIterable()) {
            a.getParent();
        }
    }
}
Exception in thread "main" spoon.reflect.declaration.ParentNotInitializedException: parent not initialized for class spoon.support.reflect.code.CtLiteralImpl (unknown file)
	at spoon.support.reflect.declaration.CtElementImpl.getParent(CtElementImpl.java:366)
	at A.main(A.java:9)

The CtLiteralImpl which represents the number 3 throws a ParentNotInitializedException when getting its parent. I guess that is not intended behaviour.

@MartinWitt
Copy link
Collaborator

Fixed by #3689

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

3 participants