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

Review fix: fix incorrect assumption in IncrementalLauncher#saveCache #3557

Merged
merged 7 commits into from
Sep 24, 2020

Conversation

LakshyAAAgrawal
Copy link
Contributor

@LakshyAAAgrawal LakshyAAAgrawal commented Aug 30, 2020

Fix #3404
I am not sure if this should treated as a bug or not, since essentially the source jar file is not present/visible to spoon.

@LakshyAAAgrawal LakshyAAAgrawal changed the title test: Add failing testcase for IncrementalLauncher saveCache Review test: Add failing testcase for IncrementalLauncher saveCache Aug 30, 2020
@monperrus
Copy link
Collaborator

Thanks, does it successfully reproduce the buggy behavior described in #3404? Which assertion is failing?

@LakshyAAAgrawal
Copy link
Contributor Author

Generated by this testcase:

spoon.support.compiler.SnippetCompilationError: The import soot cannot be resolved at src/test/resources/incremental/saveCacheIssue3404/A.java:3
	at spoon.test.model.IncrementalLauncherTest.testSaveCacheIssue3404(IncrementalLauncherTest.java:241)

Reported by user:

spoon.support.compiler.SnippetCompilationError: The import org.apache.ibatis cannot be resolved 
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.reportProblemsWhenCompiling(JDTBasedSpoonCompiler.java:590) 
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.compile(JDTBasedSpoonCompiler.java:160)
at spoon.IncrementalLauncher.saveCache(IncrementalLauncher.java:267)

The error is raised in the saveCache() function call in both cases and pertains to SnippetCompilationError regarding unresolved import from missing jar file.

In the test case, if the line containing the actual jar file in sourceClasspath is uncommented, the test passes.

Set<String> sourceClasspath = Collections.singleton("./src/test/resources/incremental/saveCacheIssue3404/soot_jar/sootclasses-trunk-jar-with-dependencies.jar");
//Set<String> sourceClasspath = Collections.EMPTY_SET;

@monperrus
Copy link
Collaborator

Thanks for the explanation, it seems that it is the same bug.

I suspect that the fix consists of ensuring that saveCache works in NOCLASSPATH mode. It should be easy.

Would you make a try and find a fix?

Thanks!

@LakshyAAAgrawal
Copy link
Contributor Author

LakshyAAAgrawal commented Sep 1, 2020

Sure. I will push the fix once I am able to solve the issue. Thanks for the suggestion.

@monperrus
Copy link
Collaborator

monperrus commented Sep 1, 2020 via email

@LakshyAAAgrawal
Copy link
Contributor Author

I am still working on the issue. Here are some observations:

I tested the "Launcher" class with the same testcase and it works and also compiles. Then further I tried to understand where might "IncrementalLauncher" be setting an expected classpath. I tried to call factory.getEnvironment().setNoClasspath(true) from various different places - The testcase, beginning of constructor call, end of constructor call, saveCache, etc. But it still does not work in NOCLASSPATH mode. Printing the value of "getArguments().getString("cpmode")" which is used to initialize the super Launcher class reports NOCLASSPATH mode. So it looks like it should be working in NOCLASSPATH mode but it does not. I suspect that some changes will need to be made in the IncrementalLauncher constructor since unlike Launcher class, the input resources for IncrementalLauncher are added in the constructor call itself.

I will continue to work on the issue and any suggestions are welcome.

@monperrus
Copy link
Collaborator

Thanks for the analysis.

I suspect that some changes will need to be made in the IncrementalLauncher constructor since unlike Launcher class, the input resources for IncrementalLauncher are added in the constructor call itself.

Agree!

@LakshyAAAgrawal
Copy link
Contributor Author

I have tried different changes in the incrementalLauncher constructor as well as saveCache, but I have not been able to solve the issue. I might be missing a very basic point, and I would be very happy if someone could please guide me on how to progress with the issue.

I have tried the following things:

  1. Compare the values within "processArguments" for the constructor call for "Launcher" as well as "IncrementalLauncher". All the argument values for both the classes are same. So that couldn't have caused a difference.
  2. Setting "getEnvironment().setNoClasspath(true);" at the beginning of the constructor call.
  3. Setting factory.getEnvironment().setNoClasspath(true) under "forceRebuild" branch.
  4. Setting oldFactory.getEnvironment().setNoClasspath(true) under (not "forceRebuild") branch.
  5. "getModelBuilder().getFactory().getEnvironment().setNoClasspath(true);" before call to compile.

Reading IncrementalLauncher code, I am not able to determine where might the behaviour difference between "IncrementalLauncher" and "Launcher" occurs.

The line launcher.buildModel() calls modelBuilder.build() which is marked saying it should be only called once for a given factory. I executed a test for "Launcher" class which was succefully building the model in NOCLASSPATH mode. I called buildmodel for it and then ran compile, and that raised the same error. So I think that calling launcher.buildModel() before saveCache() might be causing an issue, so I have removed the line temprorarily.

I have also explored a few other options but none yielded any result. Could someone suggest a direction to explore?

@monperrus
Copy link
Collaborator

Hi @LakshyAAAgrawal finally looked at this.

The problem is that method saveCache calls compile, which obviously does not work in noclasspath.

Pushed to your branch, see the fix here.

Thanks a lot for the failing test case, it was super useful.

@monperrus monperrus changed the title Review test: Add failing testcase for IncrementalLauncher saveCache Review fix: fix incorrect assumption in IncrementalLauncher#saveCache Sep 23, 2020
@nharrand nharrand merged commit 34b99e0 into INRIA:master Sep 24, 2020
@nharrand
Copy link
Collaborator

Thanks a lot for the PR!

@monperrus monperrus mentioned this pull request Oct 14, 2020
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 this pull request may close these issues.

IncrementalLauncher invoke saveCache error
3 participants