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

Do not exit JVM if a repair raises an exception #605

Open
algomaster99 opened this issue Sep 29, 2021 · 1 comment
Open

Do not exit JVM if a repair raises an exception #605

algomaster99 opened this issue Sep 29, 2021 · 1 comment

Comments

@algomaster99
Copy link
Member

I was running sorald on https://github.com/scoophealth/oscar and I saw that repairs corresponding to some rule keys were throwing an exception which exited the JVM. For example, sorald repair --source . --rule-key S1068 repairs some of the violations but the command doesn't execute successfully because an IllegalStateException is thrown. Error log:

WARN  Invalid character encountered in file fromString at line 174 for encoding UTF-16. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
INFO  JavaClasspath initialization
INFO  JavaClasspath initialization (done) | time=22ms
INFO  JavaTestClasspath initialization
INFO  JavaTestClasspath initialization (done) | time=1ms
INFO  Java Main Files AST scan
INFO  4420 source files to be analyzed
INFO  549/4420 files analyzed, current file: src/main/java/org/oscarehr/eyeform/web/OcularProcPrint.java
INFO  1208/4420 files analyzed, current file: src/main/java/org/oscarehr/ws/rest/conversion/EFormConverter.java
INFO  1997/4420 files analyzed, current file: src/main/java/org/oscarehr/common/model/IntegratorProgressItem.java
INFO  3047/4420 files analyzed, current file: src/main/java/oscar/oscarProvider/data/ProviderBillCenter.java
INFO  3814/4420 files analyzed, current file: src/main/java/oscar/form/FrmBCClientChartChecklistRecord.java
INFO  4420/4420 source files have been analyzed
INFO  Java Main Files AST scan (done) | time=59086ms
INFO  Java Test Files AST scan
INFO  0 source files to be analyzed
INFO  Java Test Files AST scan (done) | time=1ms
INFO  Java Generated Files AST scan
INFO  0/0 source files have been analyzed
INFO  0 source files to be analyzed
INFO  Java Generated Files AST scan (done) | time=1ms
INFO  0/0 source files have been analyzed
java.lang.IllegalStateException
	at spoon.support.sniper.internal.ModificationStatus.toBoolean(ModificationStatus.java:30)
	at spoon.support.sniper.SniperJavaPrettyPrinter$2.printSourceFragment(SniperJavaPrettyPrinter.java:319)
	at spoon.support.sniper.internal.AbstractSourceFragmentPrinter.print(AbstractSourceFragmentPrinter.java:64)
	at spoon.support.sniper.internal.SourceFragmentContextNormal.print(SourceFragmentContextNormal.java:38)
	at spoon.support.sniper.SniperJavaPrettyPrinter.executePrintEventInContext(SniperJavaPrettyPrinter.java:366)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:301)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:61)
	at spoon.reflect.visitor.ElementPrinterHelper.writeElementList(ElementPrinterHelper.java:184)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.visitCtClass(DefaultJavaPrettyPrinter.java:647)
	at spoon.support.reflect.declaration.CtClassImpl.accept(CtClassImpl.java:58)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.scan(DefaultJavaPrettyPrinter.java:388)
	at spoon.support.sniper.SniperJavaPrettyPrinter.lambda$superScanInContext$6(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.runInContext(SniperJavaPrettyPrinter.java:427)
	at spoon.support.sniper.SniperJavaPrettyPrinter.superScanInContext(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.access$300(SniperJavaPrettyPrinter.java:62)
	at spoon.support.sniper.SniperJavaPrettyPrinter$2.printSourceFragment(SniperJavaPrettyPrinter.java:341)
	at spoon.support.sniper.internal.AbstractSourceFragmentPrinter.print(AbstractSourceFragmentPrinter.java:64)
	at spoon.support.sniper.internal.SourceFragmentContextList.print(SourceFragmentContextList.java:19)
	at spoon.support.sniper.SniperJavaPrettyPrinter.executePrintEventInContext(SniperJavaPrettyPrinter.java:366)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:301)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:61)
	at spoon.reflect.visitor.ElementPrinterHelper.writeElementList(ElementPrinterHelper.java:184)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.visitCtClass(DefaultJavaPrettyPrinter.java:647)
	at spoon.support.reflect.declaration.CtClassImpl.accept(CtClassImpl.java:58)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.scan(DefaultJavaPrettyPrinter.java:388)
	at spoon.support.sniper.SniperJavaPrettyPrinter.lambda$superScanInContext$6(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.runInContext(SniperJavaPrettyPrinter.java:427)
	at spoon.support.sniper.SniperJavaPrettyPrinter.superScanInContext(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.access$300(SniperJavaPrettyPrinter.java:62)
	at spoon.support.sniper.SniperJavaPrettyPrinter$2.printSourceFragment(SniperJavaPrettyPrinter.java:341)
	at spoon.support.sniper.internal.AbstractSourceFragmentPrinter.print(AbstractSourceFragmentPrinter.java:64)
	at spoon.support.sniper.internal.SourceFragmentContextList.print(SourceFragmentContextList.java:19)
	at spoon.support.sniper.SniperJavaPrettyPrinter$2.printSourceFragment(SniperJavaPrettyPrinter.java:330)
	at spoon.support.sniper.internal.AbstractSourceFragmentPrinter.print(AbstractSourceFragmentPrinter.java:64)
	at spoon.support.sniper.internal.SourceFragmentContextNormal.print(SourceFragmentContextNormal.java:38)
	at spoon.support.sniper.SniperJavaPrettyPrinter.executePrintEventInContext(SniperJavaPrettyPrinter.java:366)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:301)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:61)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.visitCtCompilationUnit(DefaultJavaPrettyPrinter.java:1113)
	at spoon.support.reflect.declaration.CtCompilationUnitImpl.accept(CtCompilationUnitImpl.java:407)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.scan(DefaultJavaPrettyPrinter.java:388)
	at spoon.support.sniper.SniperJavaPrettyPrinter.lambda$superScanInContext$6(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.runInContext(SniperJavaPrettyPrinter.java:427)
	at spoon.support.sniper.SniperJavaPrettyPrinter.superScanInContext(SniperJavaPrettyPrinter.java:416)
	at spoon.support.sniper.SniperJavaPrettyPrinter.access$300(SniperJavaPrettyPrinter.java:62)
	at spoon.support.sniper.SniperJavaPrettyPrinter$2.printSourceFragment(SniperJavaPrettyPrinter.java:341)
	at spoon.support.sniper.internal.AbstractSourceFragmentPrinter.print(AbstractSourceFragmentPrinter.java:64)
	at spoon.support.sniper.internal.SourceFragmentContextList.print(SourceFragmentContextList.java:19)
	at spoon.support.sniper.SniperJavaPrettyPrinter.executePrintEventInContext(SniperJavaPrettyPrinter.java:366)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:301)
	at spoon.support.sniper.SniperJavaPrettyPrinter.scan(SniperJavaPrettyPrinter.java:61)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.calculate(DefaultJavaPrettyPrinter.java:2068)
	at spoon.support.sniper.SniperJavaPrettyPrinter.lambda$calculate$4(SniperJavaPrettyPrinter.java:159)
	at spoon.support.sniper.SniperJavaPrettyPrinter.runInContext(SniperJavaPrettyPrinter.java:427)
	at spoon.support.sniper.SniperJavaPrettyPrinter.calculate(SniperJavaPrettyPrinter.java:154)
	at spoon.support.sniper.SniperJavaPrettyPrinter.printTypes(SniperJavaPrettyPrinter.java:127)
	at sorald.Repair.overwriteCompilationUnit(Repair.java:235)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at java.base/java.util.Collections$SetFromMap.forEach(Collections.java:5581)
	at sorald.Repair.lambda$repair$0(Repair.java:101)
	at java.base/java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:411)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at sorald.Repair.repair(Repair.java:97)
	at sorald.cli.RepairCommand.call(RepairCommand.java:118)
	at sorald.cli.RepairCommand.call(RepairCommand.java:35)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
	at picocli.CommandLine.access$1200(CommandLine.java:145)
	at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
	at picocli.CommandLine.execute(CommandLine.java:2058)
	at sorald.Main.main(Main.java:7)

Once this command exits, we don't know how many repairs (out of the detected violations) were done because the JVM is exited and the report displaying the number of fixes is not generated. In my opinion, this should be fixed because repairs are done (as revealed by git status), so we should know their number and, if possible, also print the number of violations it was initially trying to repair.

@slarse
Copy link
Collaborator

slarse commented Sep 29, 2021

This exception is in the sniper, i.e. at least one file couldn't be printed. A workaround would be to figure out which file causes the problem and print it with the default printer instead, which is much more stable (but wrecks the formatting if the file).

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

No branches or pull requests

2 participants