Slackbot
04/12/2023, 5:24 AMAnze Sodja
04/13/2023, 4:06 PMQuestion: are other types in the same package reachable from the type’s AST?They are reachable, since they are probably on the compile classpath. BUT: incremental compilation might not work correctly, if you will reach them and try to do some decision based on that. Example: Java sources:
a/A.java with @MyAnnotation that create a class AList, with a list of all classes in the package
a/B.java
So when we do first compilation and we reach other types, everything works ok, because Gradle does full recompilation:
1. a/A.java is compiled to a/A.class
2. a/B.java is compiled to b/B.class
3. a/A.java generates a/AList.java with content below
4. a/AList.java is compiled to a/AList.class
package a;
class AList {
public List<String> getClasses() {
return Arrays.asList("a.A", "a.B");
}
}
All good.
But what happens when we delete a/B.java? Gradle doesn’t know that A, AList and B are related. So A won’t be passed to the compiler on incremental compilation and a/AList.java wont’ be updated.
And due to that AList.getClasses() will still return Arrays.asList("a.A", "a.B")
. That is a silent failure/bug the docs is talking about.Anze Sodja
04/13/2023, 4:15 PMArrays.asList("a.A", "a.B")
.Mike Wacker
04/13/2023, 4:34 PMPackageElement.getEnclosedElements()
for `A`'s corresponding PackageElement
, it may only be guaranteed to return the top-level types in the package that A
depends on (including transitive dependencies), not all the top-level types in the package.
But now it seems like you can see all the top-level types in the package, even during an incremental compilation. Depending on that information, however, can introduce subtle bugs.Mike Wacker
04/13/2023, 4:37 PMOverride
in the package, your generated code needs to use @java.lang.Override
, not @Override
. (You could also detect this problem and raise an error, or just decide that you'll ignore this edge case altogether.)
On a related note, I did find a unique edge case where incremental compilation misses an error.
https://github.com/gradle/gradle/issues/24736Anze Sodja
04/13/2023, 5:16 PMOn a related note, I did find a unique edge case where incremental compilation misses an error.Yes, there are these subtle corner cases indeed.