ADDITIONAL SYSTEM INFORMATION :
System, at least: windows 11, linux.
Java, at least: 1.8.0_271, 1.8.0_402
A DESCRIPTION OF THE PROBLEM :
Compile Error: java.lang.AssertionError: isSubClass T at com.sun.tools.javac.code.Symbol.isSubClass(Symbol.java:447)
REGRESSION : Last worked in version 11.0.22
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the source code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No compilation error
ACTUAL -
java: An exception has occurred in the compiler (1.8.0_402). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java: java.lang.AssertionError: isSubClass T
java: at com.sun.tools.javac.code.Symbol.isSubClass(Symbol.java:447)
java: at com.sun.tools.javac.code.Symbol.isMemberOf(Symbol.java:456)
java: at com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:1479)
java: at com.sun.tools.javac.code.Types$ImplementationCache.implementationInternal(Types.java:2693)
java: at com.sun.tools.javac.code.Types$ImplementationCache.get(Types.java:2675)
java: at com.sun.tools.javac.code.Types.implementation(Types.java:2704)
java: at com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1539)
java: at com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1528)
java: at com.sun.tools.javac.comp.Resolve.notOverriddenIn(Resolve.java:419)
java: at com.sun.tools.javac.comp.Resolve.isAccessible(Resolve.java:405)
java: at com.sun.tools.javac.comp.Resolve.isAccessible(Resolve.java:365)
java: at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1463)
java: at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1633)
java: at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1725)
java: at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1677)
java: at com.sun.tools.javac.comp.Resolve$MethodReferenceLookupHelper.lookup(Resolve.java:3192)
java: at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3348)
java: at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3333)
java: at com.sun.tools.javac.comp.Resolve.getMemberReference(Resolve.java:2741)
java: at com.sun.tools.javac.comp.DeferredAttr$DeferredChecker.visitReference(DeferredAttr.java:1183)
java: at com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:1973)
java: at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
java: at com.sun.tools.javac.comp.DeferredAttr$FilterScanner.scan(DeferredAttr.java:913)
java: at com.sun.tools.javac.comp.DeferredAttr.isDeferred(DeferredAttr.java:1100)
java: at com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:670)
java: at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1816)
java: at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
java: at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
java: at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:625)
java: at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1593)
java: at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
java: at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
java: at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
java: at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1124)
java: at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
java: at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1013)
java: at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
java: at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4364)
java: at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4272)
java: at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4201)
java: at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4176)
java: at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
java: at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
java: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
java: at com.sun.tools.javac.main.Main.compile(Main.java:523)
java: at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
java: at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:239)
java: at org.jetbrains.jps.javac.ExternalJavacProcess.compile(ExternalJavacProcess.java:189)
java: at org.jetbrains.jps.javac.ExternalJavacProcess.access$400(ExternalJavacProcess.java:28)
java: at org.jetbrains.jps.javac.ExternalJavacProcess$CompilationRequestsHandler$1.run(ExternalJavacProcess.java:262)
java: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java: at java.lang.Thread.run(Thread.java:750)
java: Compilation failed: internal java compiler error
---------- BEGIN SOURCE ----------
package com.foo.bar;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.function.Function;
class CompileErrorTest {
public enum AuthType {NONE, BASIC_HTTP, BEARER}
private final Function<AuthType, Optional<Header>> authHeaderApplier = authType -> Optional.empty();
// Leads to
// java: java.lang.AssertionError: isSubClass T
// java: at com.sun.tools.javac.code.Symbol.isSubClass(Symbol.java:447)
// java: at com.sun.tools.javac.code.Symbol.isMemberOf(Symbol.java:456)
// … etc
private <T extends HttpRequestBase> T applyAuth(@Nonnull final T request) {
authHeaderApplier.apply(AuthType.BASIC_HTTP).ifPresent(request::addHeader);
return request;
}
@Test
void testCompileErrorIsSubClassT(){
final HttpRequestBase request = applyAuth(new HttpGet("https://github.com/"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using lambda instead of method reference:
private <T extends HttpRequestBase> T applyAuth(@Nonnull final T request) {
authHeaderApplier.apply(AuthType.BASIC_HTTP).ifPresent(header -> request.addHeader(header));
return request;
}
Or using java above 8: 11, 17 works perfectly.
FREQUENCY : always