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

[Bug] NullPointerException when renaming a method using setSimpleName on a VirtualFile #6227

Open
MaxAtoms opened this issue Mar 17, 2025 · 0 comments

Comments

@MaxAtoms
Copy link

MaxAtoms commented Mar 17, 2025

Hi everyone,

I am unsure whether #3744 introduced a regression when calling setSimpleName on a model built from a VirtualFile. Is it valid to combine a VirtualFile and the SniperJavaPrettyPrinter?

Here is a minimal example that will throw a NullPointerException:

    @Test
    public void reproduction() {
        var resource = new VirtualFile("public class SomeClass { void SomeMethod() {}}");
        Launcher launcher = new Launcher();
        launcher.addInputResource(resource);
        launcher.getEnvironment().setPrettyPrinterCreator(
                () -> new spoon.support.sniper.SniperJavaPrettyPrinter(launcher.getEnvironment())
        );
        launcher.buildModel();
        var model = launcher.getModel();
        var executables = model.getElements(new TypeFilter<>(CtExecutable.class));
        var element = executables.get(1);
        element.setSimpleName("SomeOtherMethod");
    }

Exception location:
https://github.com/INRIA/spoon/pull/3744/files#diff-befbcc64ff160d86d9fa914487968edee1031311321a89dafbae1d0f69e4ee3bR254

spoon.support.sniper.internal.ElementSourceFragment.fromSameFile as the SourcePosition.getFile() call returns null.

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