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

Analyzing project creates a NullPointerException #3514

Closed
layornos opened this issue Jul 31, 2020 · 8 comments · Fixed by #3515
Closed

Analyzing project creates a NullPointerException #3514

layornos opened this issue Jul 31, 2020 · 8 comments · Fixed by #3515

Comments

@layornos
Copy link

Hi @ll,

when I try analyzing the project [1] I am getting the following exception

[main] INFO spoon.Launcher - Running in NOCLASSPATH mode (doc: http://spoon.gforge.inria.fr/launcher.html).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable StereotypeAPI at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.action.repository/src/org/palladiosimulator/simulizar/action/repository/black/ProfilesLibrary.java:76).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable LOGGER at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.action/src-man/org/palladiosimulator/simulizar/action/interpreter/TransientEffectInterpreter.java:371).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable state at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.action/src-man/org/palladiosimulator/simulizar/action/interpreter/TransientEffectInterpreter.java:373).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable LOGGER at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.action/src-man/org/palladiosimulator/simulizar/action/interpreter/TransientEffectInterpreter.java:396).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MetricDescriptionUtility at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.slidingwindow/src/org/palladiosimulator/simulizar/slidingwindow/probeframework/SlidingWindowProbeFrameWorkListenerDecorator.java:100).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MetricDescriptionUtility at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar.slidingwindow/src/org/palladiosimulator/simulizar/slidingwindow/runtimemeasurement/SlidingWindowRuntimeMeasurementsRecorder.java:88).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MetricDescriptionUtility at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/interpreter/listener/DeferredMeasurementInitialization.java:66).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable Supplier at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/interpreter/listener/DeferredMeasurementInitialization.java:70).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MetricDescriptionUtility at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/interpreter/listener/DeferredMeasurementInitialization.java:122).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable String at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/modelobserver/ResourceEnvironmentSyncer.java:289).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MetricDescriptionUtility at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/utils/MonitorRepositoryUtil.java:72).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable MonitorRepositoryUtil at (./Palladio-Analyzer-SimuLizar/bundles/org.palladiosimulator.simulizar/src/org/palladiosimulator/simulizar/utils/MonitorRepositoryUtil.java:200).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable SimuLizarMockUtils at (./Palladio-Analyzer-SimuLizar/tests/org.palladiosimulator.simulizar.tests/src/org/palladiosimulator/simulizar/test/SimuLizarTestExtension.java:73).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable e at (./Palladio-Analyzer-SimuLizar/tests/org.palladiosimulator.simulizar.tests/src/org/palladiosimulator/simulizar/test/SimuLizarTestExtension.java:100).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable Streams at (./Palladio-Analyzer-SimuLizar/tests/org.palladiosimulator.simulizar.tests/src/org/palladiosimulator/simulizar/test/SimuLizarTestExtension.java:142).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable EcoreUtil at (./Palladio-Analyzer-SimuLizar/tests/org.palladiosimulator.simulizar.tests/src/org/palladiosimulator/simulizar/test/SimuLizarTestExtension.java:142).
[main] DEBUG spoon.support.compiler.jdt.JDTTreeBuilder - Could not find declaration for variable e at (./Palladio-Analyzer-SimuLizar/tests/org.palladiosimulator.simulizar.tests/src/org/palladiosimulator/simulizar/test/SimuLizarTestExtension.java:165).
Exception in thread "main" java.lang.NullPointerException
	at spoon.support.reflect.declaration.CtTypeImpl.getPackageReference(CtTypeImpl.java:312)
	at spoon.support.reflect.declaration.CtTypeImpl.shouldIncludeSamePackage(CtTypeImpl.java:286)
	at spoon.support.reflect.declaration.CtTypeImpl.getUsedTypes(CtTypeImpl.java:278)
	at App.lambda$main$1(App.java:13)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
	at App.main(App.java:12)

Process finished with exit code 1

The minimal example to reproduce the exception looks as follows:

import spoon.Launcher;
import spoon.reflect.CtModel;

public class App {
    public static void main(String[] args) {
        // https://github.com/PalladioSimulator/Palladio-Analyzer-SimuLizar
        String path = "./Palladio-Analyzer-SimuLizar";
        Launcher launcher = new Launcher();
        launcher.addInputResource(path);
        launcher.getEnvironment().setNoClasspath(true);
        CtModel model = launcher.buildModel();

        model.getAllTypes().forEach(type -> {
            type.getUsedTypes(false).forEach(usedType -> {
                System.out.println(usedType.getSimpleName());
            });
        });
    }
}

I am new to Spoon, thus I have no idea whether it is my fault or if there might be a bug.

Regards,
Sandro

[1] https://github.com/PalladioSimulator/Palladio-Analyzer-SimuLizar

@layornos layornos changed the title Analyzing Project creates a NullPointerException Analyzing project creates a NullPointerException Jul 31, 2020
@monperrus
Copy link
Collaborator

Thanks a lot for the bug report, which version are you using?

@MartinWitt
Copy link
Collaborator

MartinWitt commented Aug 1, 2020

I can reproduce the bug with version 8.2.
Currently looking into it. The problem is, in CtTypeImpl#getPackageReference tref = tref.getDeclaringType(); returns null inside the loop

@layornos
Copy link
Author

layornos commented Aug 1, 2020

Thanks a lot for the bug report, which version are you using?

8.3.0-beta-1

@MartinWitt
Copy link
Collaborator

#3515 fixes the bug.

@monperrus
Copy link
Collaborator

@layornos do you confirm that #3515 fixes the bug?

@layornos
Copy link
Author

layornos commented Aug 1, 2020

What I've done to test the fix:

  • Downloaded the sources with the fix and built it with mvn clean install -DskipTests
  • Added the spoon-core-8.3.0-SNAPSHOT-jar-with-dependencies.jar to my local maven repository via mvn install:install-file -Dfile=spoon-core-8.3.0-SNAPSHOT-jar-with-dependencies.jar -DgroupId=fr.inria.gforge.spoon -DartifactId=spoon-core -Dversion=local_alldependencies -Dpackaging=jar -DgeneratePom=true
  • I've added the minimal example to my current spring project, there I get the following exception:
Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.base/java.util.TimSort.mergeHi(TimSort.java:903)
	at java.base/java.util.TimSort.mergeAt(TimSort.java:520)
	at java.base/java.util.TimSort.mergeCollapse(TimSort.java:448)
	at java.base/java.util.TimSort.sort(TimSort.java:245)
	at java.base/java.util.Arrays.sort(Arrays.java:1516)
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:353)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:210)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
	at java.base/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
	at java.base/java.lang.Iterable.forEach(Iterable.java:74)
	at App.lambda$main$1(App.java:13)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at App.main(App.java:13)
  • I also created a new minimal maven project [1] and added only the dependency to my locally built spoon version, when I run this version, I am getting the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/StackLocator$FqcnCallerLocator
	at org.apache.logging.log4j.util.StackLocator.<clinit>(StackLocator.java:37)
	at org.apache.logging.log4j.util.StackLocatorUtil.<clinit>(StackLocatorUtil.java:33)
	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:588)
	at spoon.Launcher.<clinit>(Launcher.java:589)
	at foo.App.main(App.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.util.StackLocator$FqcnCallerLocator
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 5 more
Process finished with exit code 1
  • If I add version 8.2.0 to the minimal maven project, I will get the NPE.

I can reproduce this behaviour on Mac as well as on Windows.

[1] https://github.com/layornos/SpoonTestFixIssue3514

@monperrus
Copy link
Collaborator

I've added the minimal example to my current spring project, there I get the following exception: `Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!`

That's a different error. Would you create a new issue or PR with a failing test case? That would be super useful!

@MartinWitt
Copy link
Collaborator

After a short slack chat, I found the reason for his bug. Try to formulate the bugfix in a real PR later.

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

Successfully merging a pull request may close this issue.

3 participants