From f8d431ae4461a65ab109c0b8afffdfbcc5a12a5b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 18 Oct 2021 16:43:53 -0400 Subject: [PATCH] LUCENE-10185: pass --release 11 to ECJ linter, fix JDK 17 build (#393) * LUCENE-10185: pass --release 11 to ECJ linter, fix JDK 17 build Otherwise, new java releases such as JDK 18, JDK 19, ... may have even more new deprecations, the build shouldn't fail in such cases. Remove -source/-target now that we pass --release Fix casting so ECJ understands it and creates correct call signature (UweSays: "It's ok. I know why it happens, but it's a bug in ECJ. The type safety is checked by the invokeexact") Co-authored-by: Uwe Schindler --- gradle/validation/ecj-lint.gradle | 3 +-- .../src/java/org/apache/lucene/util/AttributeFactory.java | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gradle/validation/ecj-lint.gradle b/gradle/validation/ecj-lint.gradle index 8c72f9d30f9..2b49717a9e0 100644 --- a/gradle/validation/ecj-lint.gradle +++ b/gradle/validation/ecj-lint.gradle @@ -63,8 +63,7 @@ allprojects { args += [ "-d", "none" ] // Compilation environment. - args += [ "-source", project.java.sourceCompatibility ] - args += [ "-target", project.java.targetCompatibility ] + args += [ "--release", project.java.targetCompatibility ] args += [ "-encoding", "UTF-8"] args += [ "-proc:none" ] args += [ "-nowarn" ] diff --git a/lucene/core/src/java/org/apache/lucene/util/AttributeFactory.java b/lucene/core/src/java/org/apache/lucene/util/AttributeFactory.java index b5b1dd70afb..4e3de2db6a3 100644 --- a/lucene/core/src/java/org/apache/lucene/util/AttributeFactory.java +++ b/lucene/core/src/java/org/apache/lucene/util/AttributeFactory.java @@ -149,9 +149,13 @@ public abstract class AttributeFactory { final MethodHandle constr = findAttributeImplCtor(clazz); return new StaticImplementationAttributeFactory(delegate, clazz) { @Override + @SuppressWarnings("unchecked") protected A createInstance() { try { - return (A) constr.invokeExact(); + // be explicit with casting, so javac compiles correct call to polymorphic signature: + final AttributeImpl impl = (AttributeImpl) constr.invokeExact(); + // now cast to generic type: + return (A) impl; } catch (Error | RuntimeException e) { throw e; } catch (Throwable e) {