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: Spoon crashes because of module-info.java when building model #3417

Closed
henry-lp opened this issue Jun 14, 2020 · 10 comments
Closed

bug: Spoon crashes because of module-info.java when building model #3417

henry-lp opened this issue Jun 14, 2020 · 10 comments
Labels

Comments

@henry-lp
Copy link

henry-lp commented Jun 14, 2020

java.lang.IllegalStateException: Module should be known was thrown when I load this project and tried to build a model with it. Before that Spoon demands that the compliance level should be set to 9 and the error was thrown after it was set in Spoon enviroment.

All other spoon configurations during run, please check this file

To reproduce :

git clone https://github.com/SpoonLabs/sorald.git

cd sorald

mvn package -DskipTests

git clone https://github.com/eclipse/openj9 Repo4Analyze

java -jar target/sorald-1.1-SNAPSHOT-jar-with-dependencies.jar --originalFilesPath Repo4Analyze/ --ruleKeys 2184 --maxFixesPerRule 1

Error output log:

Exception in thread "main" java.lang.IllegalStateException: Module should be known
	at org.eclipse.jdt.internal.compiler.batch.CompilationUnit.module(CompilationUnit.java:126)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.module(CompilationUnitDeclaration.java:847)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:470)
	at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:854)
	at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:394)
	at spoon.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:60)
	at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:256)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnits(JDTBasedSpoonCompiler.java:417)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:369)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:337)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:114)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:97)
	at spoon.Launcher.buildModel(Launcher.java:755)
	at sorald.DefaultRepair.createLauncher(DefaultRepair.java:128)
	at sorald.DefaultRepair.repair(DefaultRepair.java:60)
	at sorald.Main.start(Main.java:137)
	at sorald.Main.main(Main.java:143)
@monperrus
Copy link
Collaborator

This depends on the used JVM.

Which JVM do you use? Could you try with some other versions?

@darius-sas
Copy link
Contributor

darius-sas commented Sep 3, 2020

Hi,

I'm encountering similar issues while analysing other projects as well.

Here are the details of my environment:

Java:

openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.119.04, mixed mode, sharing)

Spoon:

<groupId>fr.inria.gforge.spoon</groupId>
<artifactId>spoon-core</artifactId>
<version>8.2.0</version>

Spoon Environment:

environment.setEncoding(StandardCharsets.UTF_8);
environment.disableConsistencyChecks();
environment.setComplianceLevel(9); // tried even with 13
environment.setIgnoreDuplicateDeclarations(true);
environment.setCommentEnabled(false);
environment.setNoClasspath(true);
environment.setShouldCompile(false);

This happens regardless of what Launcher I use, Launcher directly or MavenLauncher.
Tried different environment settings too, but no success so far.

At the moment, the only workaround I have for this issue is to ensure Spoon doesn't see the module-info.java file, by passing as input resource the src/main/java/com instead of src/main/java.

@monperrus
Copy link
Collaborator

Thanks for the additional info. Does the bug also happen with OpenJDK 9?

@darius-sas
Copy link
Contributor

I cannot compile my project with Java 9 (only 11 or above), but I created a new project and get the same issue using OpenJDK 9 analysing Joda-Beans with the same settings I mentioned in my previous comment.

$ java -jar target/untitled-1.0-SNAPSHOT-jar-with-dependencies.jar joda-beans/src/main/java
Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalStateException: Module should be known
	at org.eclipse.jdt.internal.compiler.batch.CompilationUnit.module(CompilationUnit.java:126)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.module(CompilationUnitDeclaration.java:847)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:470)
	at org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:854)
	at org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:394)
	at spoon.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:60)
	at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:256)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnits(JDTBasedSpoonCompiler.java:417)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:369)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:337)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:114)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:97)
	at spoon.Launcher.buildModel(Launcher.java:755)
	at com.company.Main.main(Main.java:42)

The Java version I used:

openjdk version "9.0.1"
OpenJDK Runtime Environment (build 9.0.1+11)
OpenJDK 64-Bit Server VM (build 9.0.1+11, mixed mode)

Link to download my test project:
untitled.zip

Commit hash of Joda beans: 6ffbe8ffe7ba64675158e0f6f5c47a190c45bb29

@monperrus
Copy link
Collaborator

Thanks.

We had a recent change in the module code #3549

Could you try with master?

@darius-sas
Copy link
Contributor

Now it crashes with NullPointerException

$ java9 -jar target/untitled-8.3.0-SNAPSHOT-jar-with-dependencies.jar ~/data/repos/joda-beans/src
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NullPointerException
	at spoon.support.compiler.jdt.ReferenceBuilder.setPackageOrDeclaringType(ReferenceBuilder.java:1114)
	at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:704)
	at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:637)
	at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:519)
	at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:136)
	at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:130)
	at spoon.support.compiler.jdt.ReferenceBuilder.buildTypeReference(ReferenceBuilder.java:148)
	at spoon.support.compiler.jdt.JDTTreeBuilder.visit(JDTTreeBuilder.java:1527)
	at org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference.traverse(QualifiedTypeReference.java:220)
	at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.traverse(LocalDeclaration.java:478)
	at org.eclipse.jdt.internal.compiler.ast.Block.traverse(Block.java:148)
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.traverse(ForeachStatement.java:671)
	at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:365)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1591)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1463)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:826)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:787)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.lambda$buildModel$0(JDTBasedSpoonCompiler.java:437)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.forEachCompilationUnit(JDTBasedSpoonCompiler.java:466)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildModel(JDTBasedSpoonCompiler.java:435)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:372)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:337)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:114)
	at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:97)
	at spoon.Launcher.buildModel(Launcher.java:755)
	at com.company.Main.main(Main.java:43)

@monperrus monperrus changed the title A way to ignore Module when building model bug; Spoon crashes because of module-info.java when building model Sep 11, 2020
@monperrus monperrus changed the title bug; Spoon crashes because of module-info.java when building model bug: Spoon crashes because of module-info.java when building model Sep 11, 2020
@monperrus monperrus added the bug label Sep 11, 2020
@monperrus
Copy link
Collaborator

Would you be able to write a failing test case in a pull request? That would be super helpful.

@slarse
Copy link
Collaborator

slarse commented Aug 12, 2021

I believe that this was fixed in #4073, I now have no trouble parsing Joda-Beans commit 6ffbe8ffe7ba64675158e0f6f5c47a190c45bb29.

@darius-sas can you confirm that the problem is solved on your end?

@darius-sas
Copy link
Contributor

Works for me too!
Thanks for fixing.

@slarse
Copy link
Collaborator

slarse commented Aug 13, 2021

@darius-sas Thanks for confirming, I'm closing this issue then :)

@slarse slarse closed this as completed Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants