JDK-8064464 : regression with type inference of conditional expression
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-11-06
  • Updated: 2016-07-28
  • Resolved: 2014-11-12
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 9
9 b40Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Type inference doesn't work on conditional expressions that compiled with javac7.

REGRESSION.  Last worked in version 7u67

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
$ javac Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The compilation should succeed.
ACTUAL -
The compilation does not succeed.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Test.java:9: error: reference to f is ambiguous
    f(!lx.isEmpty() ? lx.get(0) : 0); // both method f(Object) in Test and method f(int) in Test match
    ^
  both method f(Object) in Test and method f(int) in Test match
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.List;

abstract class Test {
  abstract void f(Object o);
  abstract void f(int i);

  void m(List<Integer> lx) {
    f(!lx.isEmpty() ? 0 : lx.get(0)); // OK
    f(!lx.isEmpty() ? lx.get(0) : 0); // error: both method f(Object) in Test and method f(int) in Test match
  }
}

---------- END SOURCE ----------


Comments
The issue is being reproduced with jdk8 b132 on Linux x64: -bash-4.1$ uname -a Linux spb23340 2.6.39-400.211.1.el6uek.x86_64 #1 SMP Fri Nov 15 13:39:16 PST 2013 x86_64 x86_64 x86_64 GNU/Linux -bash-4.1$ /export/jdk/jdk1.8.0b132/bin/javac Test.java Test.java:9: error: reference to f is ambiguous f(!lx.isEmpty() ? lx.get(0) : 0); // error: both method f(Object) in Test and method f(int) in Test match ^ both method f(Object) in Test and method f(int) in Test match 1 error
30-10-2015

There are two issues here - the asymmetry is caused by a bug in DeferredAttr.isDeferred - which incorrectly skips deferred attribution depending on the order of the conditional expression. Then there's an issue in the check for Attr.isBooleanOrNumeric as the test should at least use instantiated signatures (before inference - that is).
10-11-2014

There are two issues here - the asymmetry is caused by a bug in DeferredAttr.isDeferred - which incorrectly skips deferred attribution depending on the order of the conditional expression. Then there's an issue in the check for Attr.isBooleanOrNumeric as the test should at least use instantiated signatures (before inference - that is).
10-11-2014

The program compiles fine with 7u67, but fails with error as mentioned with 8u25 and 8u40.
10-11-2014