refactorfirst / RefactorFirst

Identifies and prioritizes God Classes Highly Coupled classes, and Class Cycles in Java codebases you should refactor first.
Apache License 2.0
457 stars 42 forks source link

GeneratedJavaParser.generateParseException #102

Closed atkawa7 closed 1 month ago

atkawa7 commented 1 month ago
[ERROR] Failed to execute goal org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0:htmlReport (default-cli) on project ngschema: Execution default-cli of goal org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0:htmlReport failed: com.github.javaparser.ParseProblemException: (line 23,col 32) Parse error. Found ".", expected one of  "!=" "%" "%=" "&" "&&" "&=" "(" "*" "*=" "+" "+=" "," "-" "-=" "->" "/" "/=" "::" ";" "<" "<<=" "<=" "=" "==" ">" ">=" ">>=" ">>>=" "?" "^" "^=" "instanceof" "|" "|=" "||"
[ERROR] Problem stacktrace :
[ERROR]   com.github.javaparser.GeneratedJavaParser.generateParseException(GeneratedJavaParser.java:14457)
[ERROR]   com.github.javaparser.GeneratedJavaParser.jj_consume_token(GeneratedJavaParser.java:14302)
[ERROR]   com.github.javaparser.GeneratedJavaParser.FieldDeclaration(GeneratedJavaParser.java:1855)
[ERROR]   com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBodyDeclaration(GeneratedJavaParser.java:1764)
[ERROR]   com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceBody(GeneratedJavaParser.java:1286)
[ERROR]   com.github.javaparser.GeneratedJavaParser.ClassOrInterfaceDeclaration(GeneratedJavaParser.java:538)
[ERROR]   com.github.javaparser.GeneratedJavaParser.CompilationUnit(GeneratedJavaParser.java:156)
[ERROR]   com.github.javaparser.JavaParser.parse(JavaParser.java:125)
[ERROR]   com.github.javaparser.JavaParser.parse(JavaParser.java:199)
[ERROR]   com.github.javaparser.JavaParserAdapter.parse(JavaParserAdapter.java:92)
[ERROR]   com.github.javaparser.StaticJavaParser.parse(StaticJavaParser.java:142)
[ERROR]   org.hjug.parser.JavaProjectParser.getInstanceVarTypes(JavaProjectParser.java:75)
[ERROR]   org.hjug.parser.JavaProjectParser.lambda$getClassReferences$2(JavaProjectParser.java:40)
[ERROR]   java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
[ERROR]   java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
[ERROR]   java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
[ERROR]   java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
[ERROR]   java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
[ERROR]   java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
[ERROR]   java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
[ERROR]   java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
[ERROR]   java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
[ERROR]   java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[ERROR]   java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
[ERROR]   org.hjug.parser.JavaProjectParser.getClassReferences(JavaProjectParser.java:39)
[ERROR]   org.hjug.cbc.CostBenefitCalculator.runCycleAnalysis(CostBenefitCalculator.java:77)
[ERROR]   org.hjug.refactorfirst.report.HtmlReport.runCycleAnalysis(HtmlReport.java:178)
[ERROR]   org.hjug.refactorfirst.report.SimpleHtmlReport.execute(SimpleHtmlReport.java:162)
[ERROR]   org.hjug.mavenreport.RefactorFirstHtmlReport.execute(RefactorFirstHtmlReport.java:43)
[ERROR]   org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
[ERROR]   org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
[ERROR]   org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
[ERROR]   org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
[ERROR]   org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
[ERROR]   org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
[ERROR]   org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
[ERROR]   org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
[ERROR]   org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
[ERROR]   org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
[ERROR]   org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
[ERROR]   org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
[ERROR]   org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
[ERROR]   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]   java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]   java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]   java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]   org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
[ERROR]   org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
[ERROR]   org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
[ERROR]   org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
jimbethancourt commented 1 month ago

Hi @atkawa7 - thank you for the stacktrace! It looks like this may be an issue with the JavaParser library.

Could you provide sample code that reproduces the issue? I'd be happy to try and resolve the issue if it can be reproduced.

Since this does appear to be an issue with the JavaParser library, it may require a fix there, which is something that is (likely) out of my control, though I can pass along the stacktrace and the code that reproduces the issue.

I have recently considered using a different parser, which could also resolve the issue.

Thanks!

agentgt commented 1 month ago

@jimbethancourt I'm having all sorts of parser errors as well and because the filename is not outputted it is quite painful to go off and reproduce code.

https://www.reddit.com/r/java/comments/1fpb8ex/refactorfirst_050_is_released/lp7964b/

It appears the parser does not like inline local classes but also as issues with sealed classes.

jimbethancourt commented 1 month ago

Logging classes as they are being parsed. Please try 0.6.0

atkawa7 commented 1 month ago

@jimbethancourt I have looked. It seems this library is passing any file with .java extension it finds. We have our sample codes in ours docs folder being parsed which are not part of the source. Is there a way to exclude the folder?