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

Incremental java compilation fails when renaming classname with $ character #19257

Closed
horseunnamed opened this issue Dec 8, 2021 · 4 comments · Fixed by #19274
Closed

Incremental java compilation fails when renaming classname with $ character #19257

horseunnamed opened this issue Dec 8, 2021 · 4 comments · Fixed by #19274
Labels
a:bug a:regression This used to work affects-version:7.3 @execution Issues owned by execution team in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures
Milestone

Comments

@horseunnamed
Copy link

horseunnamed commented Dec 8, 2021

Issue occurs since Gradle 7.3. Tested with OpenJDK 11 and 13. Tiny reproduction sample is here: https://github.com/horseunnamed/Gradle-change-detection-issue

Expected Behavior

Incremental java compilation is successful when classname with $ is renamed (as it is with Gradle 7.2 and earlier versions)

Current Behavior

After changing java class name with $ character and running incremental build we get the error:

> Task :compileJava FAILED
Caching disabled for task ':compileJava' because:
  Build cache is disabled
Task ':compileJava' is not up-to-date because:
  Input property 'stableSources' file .../src/main/java/issue/Class$Name.java has been removed.
  Input property 'stableSources' file .../src/main/java/issue/Main.java has changed.
  Input property 'stableSources' file .../src/main/java/issue/Class$NameChanged.java has been added.
Created classpath snapshot for incremental compilation in 0.0 secs.
Compiling with toolchain '/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home'.
Compiling with JDK Java compiler API.
.../src/main/java/issue/Main.java:5: error: cannot find symbol
        new Class$NameChanged();
            ^
  symbol:   class Class$NameChanged
  location: class Main
1 error
Incremental compilation of 3 classes completed in 0.012 secs.
:compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.02 secs.

FAILURE: Build failed with an exception.

Context

On our real world Android-project we had a very harmful impact from this issue when upgrading Gradle version to 7.3.1.
Incremental annotation processor in our project generates some files with dollar sign and this issue silently led us to ClassNotFoundException at runtime in some cases.
It's very serious blocker for us to upgrade from 7.2.

Steps to Reproduce

Please see reproduction sample: https://github.com/horseunnamed/Gradle-change-detection-issue

  1. Run build task to compile java project with classname that conatins dollar sign (e.g. Class$Name.java) and reference to it somewhere else (from Main.java in my reproduction sample)
  2. Change classname and reference to it with something that still contains dollar sign
  3. Rerun build task
  4. Get mentioned incremental compilation error

Your Environment

Build scan of failed incremental build from reproduction sample: https://scans.gradle.com/s/b4qlo2umn7dms

@big-guy big-guy added the a:regression This used to work label Dec 8, 2021
@big-guy big-guy added this to the 7.4 RC1 milestone Dec 8, 2021
@octylFractal octylFractal added in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures and removed to-triage labels Dec 8, 2021
@big-guy big-guy added the @execution Issues owned by execution team label Dec 9, 2021
@asodja
Copy link
Member

asodja commented Dec 10, 2021

@horseunnamed PR with the fix will be merged soon. Can you maybe share the name of the annotation processor? Is this some popular annotation processor in the Android world?

We would like to find out how many users might be affected by this issue.

@horseunnamed
Copy link
Author

horseunnamed commented Dec 10, 2021

@asodja, thanks for fixing this issue so quickly!
On real project we faced this issue with annotation processor from Toothpick library.
I also have a more complex reproducer with annotation processor from Toothpick. It's very close to our real project issue. See README from this sample for details.

@asodja
Copy link
Member

asodja commented Dec 10, 2021

Thank you for that info. Note that the fix is already on the latest nightly. Can you maybe try it and confirm that that fixes the issue? Here is the info on how you can update the wrapper: https://gradle.org/nightly/

@horseunnamed
Copy link
Author

horseunnamed commented Dec 13, 2021

I've tried to reproduce this issue on our real project with latest nightly build and can confirm that issue was fixed :)
Thanks again!

@ljacomet ljacomet modified the milestones: 7.4 RC1, 7.3.2 Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug a:regression This used to work affects-version:7.3 @execution Issues owned by execution team in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants