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] SniperJavaPrettyPrinter fails because CtRecord does not identify CtParameter role #5968

Open
aebute1 opened this issue Sep 3, 2024 · 2 comments

Comments

@aebute1
Copy link

aebute1 commented Sep 3, 2024

When performing a type name refactor using the sniperjavapretty printer, I get the error: The element of class class spoon.support.reflect.declaration.CtRecordImpl does not have CtRole.PARAMETER.

The stack trace is as shown below:

Exception in thread "main" spoon.SpoonException: The element of class class spoon.support.reflect.declaration.CtRecordImpl does not have CtRole.PARAMETER
	at spoon.reflect.meta.impl.RoleHandlerHelper.getRoleHandler(RoleHandlerHelper.java:54)
	at spoon.support.sniper.internal.ElementSourceFragment.getRoleHandler(ElementSourceFragment.java:271)
	at spoon.support.sniper.internal.ElementSourceFragment.addChild(ElementSourceFragment.java:244)
	at spoon.support.sniper.internal.ElementSourceFragment$1.enter(ElementSourceFragment.java:202)
	at spoon.reflect.visitor.CtScanner.visitCtParameter(CtScanner.java:699)
	at spoon.support.reflect.declaration.CtParameterImpl.accept(CtParameterImpl.java:56)
	at spoon.reflect.visitor.EarlyTerminatingScanner.doScan(EarlyTerminatingScanner.java:145)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:121)
	at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:189)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:106)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:83)
	at spoon.reflect.visitor.CtScanner.visitCtConstructor(CtScanner.java:394)
	at spoon.support.reflect.declaration.CtConstructorImpl.accept(CtConstructorImpl.java:48)
	at spoon.reflect.visitor.EarlyTerminatingScanner.doScan(EarlyTerminatingScanner.java:145)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:121)
	at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:189)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:106)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:83)
	at spoon.reflect.visitor.CtScanner.visitCtRecord(CtScanner.java:1073)
	at spoon.support.reflect.declaration.CtRecordImpl.accept(CtRecordImpl.java:100)
	at spoon.reflect.visitor.EarlyTerminatingScanner.doScan(EarlyTerminatingScanner.java:145)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:121)
	at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:189)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:106)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:83)
	at spoon.reflect.visitor.EarlyTerminatingScanner.visitCtCompilationUnit(EarlyTerminatingScanner.java:160)
	at spoon.support.reflect.declaration.CtCompilationUnitImpl.accept(CtCompilationUnitImpl.java:408)
	at spoon.reflect.visitor.EarlyTerminatingScanner.doScan(EarlyTerminatingScanner.java:145)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:121)
	at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:189)
	at spoon.reflect.visitor.EarlyTerminatingScanner.scan(EarlyTerminatingScanner.java:106)
	at spoon.support.sniper.internal.ElementSourceFragment.createSourceFragmentsFrom(ElementSourceFragment.java:230)
	at spoon.support.reflect.declaration.CtCompilationUnitImpl.getOriginalSourceFragment(CtCompilationUnitImpl.java:360)
	at spoon.support.modelobs.SourceFragmentCreator.onChange(SourceFragmentCreator.java:32)
	at spoon.support.modelobs.ChangeCollector$ChangeListener.onObjectUpdate(ChangeCollector.java:176)
	at spoon.support.reflect.reference.CtReferenceImpl.setSimpleName(CtReferenceImpl.java:65)
	at spoon.refactoring.Refactoring.changeTypeName(Refactoring.java:58)
	at com.netflix.rewrite.MigrationV2.lambda$main$3(MigrationV2.java:54)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.base/java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:174)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at com.netflix.rewrite.MigrationV2.main(MigrationV2.java:54)
@aebute1 aebute1 changed the title SniperJavaPrettyPrinter fails because CtRecord does not identify CtParameter role [Bug] SniperJavaPrettyPrinter fails because CtRecord does not identify CtParameter role Sep 3, 2024
@monperrus
Copy link
Collaborator

thanks for the bug report. adding a role is a doable PR, would you give it a try?

@SirYwell
Copy link
Collaborator

This problem might be similar to #4723, do you have a (minimal) reproducible example?

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

3 participants