sdedic commented on code in PR #8810:
URL: https://github.com/apache/netbeans/pull/8810#discussion_r2381347735
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -367,11 +367,19 @@ private String dependenciesAsString(Task t,
TaskDependency td) {
}
private void detectConfigurationArtifacts(NbProjectInfoModel model) {
+ // JDK-8301046: Don't use Configuration::getName as a method
reference. The bug, when
+ // compiling `Configuration::getName` against Gradle >= 8.4, causes
javac to pick the
+ // wrong receiver target (invokeinterface on Named::getName) in the
lambda bootstrap
+ // method params rather than the (correct per JLS) invokevirtual on
the callsite's
+ // erasure type (Configuration). This will break at runtime when
calling Gradle <8.4,
+ // as in earlier versions the Configuration class does not implement
Named, and throws
+ // a BootstrapMethodError wrapping a LambdaConversionException. The
lambda form:
+ // `c -> c.getName()` bootstraps correctly but costs an extra method
def/indirection.
Review Comment:
Thanks for this explanation
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.java:
##########
@@ -1362,18 +1370,24 @@ private void detectArtifacts(NbProjectInfoModel model) {
}
}
Map<String, Object> archives = new HashMap<>();
- beforeGradle("5.2", () -> {
- // The jar.getCassifier() and jar.getArchievePath() are deprecated
since 5.2
- // These methods got removed in 8.0
- project.getTasks().withType(Jar.class).forEach(jar -> {
- archives.put(jar.getClassifier(), jar.getArchivePath());
- });
- });
- sinceGradle("5.2", () -> {
- project.getTasks().withType(Jar.class).forEach(jar -> {
- archives.put(jar.getArchiveClassifier().get(),
jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile());
- });
- });
+ Consumer<Jar> jarToArchivesClassifierAndPath =
+ sinceGradleOrDefault(
+ "5.2",
+ () -> jar -> archives.put(jar.getArchiveClassifier().get(),
jar.getDestinationDirectory().file(jar.getArchiveFileName().get()).get().getAsFile()),
+ () -> {
+ // The jar.getCassifier() and jar.getArchievePath() are
deprecated since 5.2
+ // These methods got removed in 8.0
+ Method getClassifier =
Jar.class.getMethod("getClassifier");
Review Comment:
Please could you cache the Method objects at the Builder level or at least
in the method ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists