JDK-8210483 : AssertionError in DeferredAttr at setOverloadKind caused by JDK-8203679
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 11,12
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-09-04
  • Updated: 2020-01-13
  • Resolved: 2018-09-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11
11.0.2Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

A DESCRIPTION OF THE PROBLEM :
javac throws an AssertionError if I compile the following code with JDK11+28. 

The exception will not be thrown if I compile the class with JDK 10.0.2

REGRESSION : Last worked in version 10.0.2

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac JdkBug.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class file
ACTUAL -
java.lang.AssertionError
        at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
        at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$2$1.setOverloadKind(DeferredAttr.java:172)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitReference(ArgumentAttr.java:283)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2190)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:751)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1997)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3573)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2110)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:498)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:481)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.lambda$processArg$0(ArgumentAttr.java:220)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:242)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.processArg(ArgumentAttr.java:219)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitApply(ArgumentAttr.java:307)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
        at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:751)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitNewClass(Attr.java:2192)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1689)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1866)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1546)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2598)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1807)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$4.complete(DeferredAttr.java:374)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:335)
        at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:321)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1060)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:887)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:775)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:896)
        at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:181)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:605)
        at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:644)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4120)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3913)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3814)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3803)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3696)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2110)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:695)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1174)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:956)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4683)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4574)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4503)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4448)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:311)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:170)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

---------- BEGIN SOURCE ----------
package com.java.bug

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class JdkBug {

  public static void main(String args[]) {
    List<String> commandList = Arrays.asList("command1", "command2", "command3");

    Optional<String> optionalCommandMarker = Optional.of("command2");

    Stream<CommandConfig> commandConfig = commandList.stream().map(command -> {
      return new CommandConfig(command, optionalCommandMarker.map(command::equalsIgnoreCase).orElse(false));
    });
    
    commandConfig.forEach(System.out::println);
  }

  private static class CommandConfig {
    private String command;
    private boolean isMarked;

    public CommandConfig(String command, boolean isMarked) {
      this.command = command;
      this.isMarked = isMarked;
    }

    @Override
    public String toString() {
      return "CommandConfig [command=" + command + ", isMarked=" + isMarked + "]";
    }
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Fix Request Backporting this fix makes javac more resilient, and keeps codebases in sync across releases (I see 11.0.4-oracle). Patch applies cleanly to 11u and passes langtools:tier1.
28-02-2019

The logic added in JDK-8203679 makes the assumption that "once the value for overloadKind is determined for a copy, it can be safely forwarded to the copied tree, we want to profit from that". That assumption breaks when a resolution error occurs and setOverloadKind is conservatively set to OVERLOADED [1], and then a later attribute step successfully resolves the method references and determines it is not overloaded. Relaxing the assertion in the implementation of setOverloadKind in DeferredAttr to allow the overload kind to change from the erroneous result to a successful result avoids the crash, and doesn't cause any regressions. [1] http://hg.openjdk.java.net/jdk/jdk/file/f036f767708e/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java#l283
11-09-2018

I confirmed this was introduced by the fix for JDK-8203679.
10-09-2018

This issue is regression started from 11 ea b18 onwards. 10.0.2 - pass 11 ea b17 - Pass 11 ea b18 - Fail 11 ea b28 - Fail 12 ea b09 - Fail There are three issues which got fixed in tools/javac area in b18. JDK-8204674, JDK-8204610, JDK-8203679 My primary suspect is JDK-8203679
07-09-2018