JDK-8133239 : Method reference can't see package-access tvar method
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u51
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2015-07-30
  • Updated: 2015-08-25
  • Resolved: 2015-08-25
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 b54Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux ** 4.0.0-2-amd64 #1 SMP Debian 4.0.8-2 (2015-07-22) x86_64 GNU/Linux

Java not taken from Debian repositories but self installed

also reproduced on a current Windows 7


A DESCRIPTION OF THE PROBLEM :
When having a generic typed argument, specified to be a subclass via extends, I cannot access member method from this type. For example, in "<C extends Field> void test(C field)", I cannot access fields member methods

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try to compile the attached source code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the code to compile successfully, like it does with ECJ, since there isn't any ambiguous references or something.
ACTUAL -
The code does not compile. The compiler 

Test.java:10: error: invalid method reference
        Consumer<String> setter = field::setValue;
                                  ^
  cannot find symbol
    symbol:   method setValue(String)
    location: bound of type variable C
  where C is a type-variable:
    C extends Field declared in method <C>test(C)
1 error


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.function.Consumer;
 
class Field {
    void setValue(String t) {}
}
 
class Test {
    protected <C extends Field> void test(C field) {
        Consumer<String> setter = field::setValue;
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
One simple work around would be assigning the generic variable to a new, not generic variable first:

--------
  Field f = field;
  Consumer<String> setter = f::setValue;
--------

or using a lambda instead of a method reference:

--------
  Consumer<String> setter = val -> field.setValue(val);
--------


Comments
Was fixed by JDK-8073842. (The comment about the bug being present in 9-b75 confuses me -- I see the bug in 9-b50, but fixed in 9-b60 and 9-b70.)
25-08-2015

1. Run the attached test case (Test.java). 2. When checked this for JDK 8, 8u51 and 9 ea b75, the compilation failed with following error message: javac Test.java : error: invalid method reference Consumer<String> setter = field::setValue; cannot find symbol symbol: method setValue(String) location: bound of type variable C where C is a type-variable: C extends Field declared in method <C>test(C) 1 error 3. Moving this up for further evaluation.
10-08-2015