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

java.lang.ClassCastException: spoon.support.reflect.declaration.CtAnonymousExecutableImpl cannot be cast to spoon.reflect.declaration.CtConstructor #739

Closed
arnobl opened this issue Jul 4, 2016 · 1 comment

Comments

@arnobl
Copy link
Contributor

arnobl commented Jul 4, 2016

Me, again.

Using 5.2.0, I got a:

Caused by: java.lang.ClassCastException: spoon.support.reflect.declaration.CtAnonymousExecutableImpl cannot be cast to spoon.reflect.declaration.CtConstructor
    at spoon.reflect.factory.ExecutableFactory.createReference(ExecutableFactory.java:109)
    at spoon.support.reflect.declaration.CtExecutableImpl.getReference(CtExecutableImpl.java:145)

when parsing the following code:

class Foo {
    static {
        System.out.println("fooo");
    }
}

A test case to reproduce the exception:

public void testSpoon() {
        final spoon.Launcher launcher = new spoon.Launcher();
        launcher.addInputResource("src/test/resources/java/Foo.java");
        launcher.getEnvironment().setNoClasspath(true);
        launcher.getEnvironment().setComplianceLevel(8);
        launcher.buildModel();

        launcher.getModel().getElements(new TypeFilter<CtExecutable<?>>(CtExecutable.class) {
            @Override
            public boolean matches(final CtExecutable<?> exec) {
                try {
                    System.out.println(exec.getReference());
                }catch(ClassCastException ex) {
                    fail();
                }

                return super.matches(exec);
            }
        });
    }
@GerardPaligot
Copy link
Contributor

Thanks for the report. PR done.

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

2 participants