Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 268161 - Generics type inference regression with platform JDK 1.7
Generics type inference regression with platform JDK 1.7
Product: java
Classification: Unclassified
Component: Compiler
PC Windows 7
: P1 with 3 votes (vote)
: Dev
Assigned To: Dusan Balek
Depends on:
  Show dependency treegraph
Reported: 2016-09-22 18:59 UTC by matthies
Modified: 2017-05-02 14:20 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT


Note You need to log in before you can comment on or make changes to this bug.
Description matthies 2016-09-22 18:59:04 UTC
When the Java platform is set to JDK 1.7 in the project settings, there appears to be a serious regression with generics and type inference in NB 8.2 RC.

Example code:

    import java.util.Collection;

    public abstract class Example
        public void foo(Collection<? extends Number> numbers)
            Collection<Number> copy = copyOf(numbers);

        public abstract <E> Collection<E> copyOf(Collection<? extends E> coll);

This compiles without errors on JDK 1.7, but NetBeans shows an error in the editor on the statement in foo():

incompatible types: Collection<CAP#1> cannot be converted to Collection<Number>
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Number from capture of ? extends Number

This doesn't happen on NetBeans 8.1.
Comment 1 jschneider 2016-10-05 11:12:27 UTC
reproducible with NetBeans 8.2, Ubuntu 16.04.01 64bit and Oracle JDK 7 64bit
Comment 2 matthies 2016-10-06 13:30:55 UTC
Setting this to P1 because it basically makes NetBeans 8.2 unusable with JDK 1.7.
Comment 3 cbourque 2016-10-12 19:31:13 UTC
I have also noticed the same bug and it's easily reproducible with this simple test case:

public class Test
    public void test1()
        Map<String, Object> map = new HashMap<>(test2());

    public Map<String, ?> test2()
        Map<String, ?> map = new HashMap<>();
        return map;

In NetBeans the statement in method test1() is underlined in red but it compiles just fine!
Comment 4 Svata Dedic 2016-11-04 10:43:36 UTC
Affects Compile on Save; the class contains auto-generated throw RuntimeException at the place of the reported error.

Possibly javac regression: for Source = 1.8 the compiler works OK. When source is < 1.8, types are evaluated incorrectly.
Comment 5 Svata Dedic 2016-11-04 11:02:51 UTC
Note that javac compiler team may see this P1 as 'no issue' - see
Comment 6 md_5 2017-02-01 03:23:31 UTC
I can reproduce this as well in 8.2, both in my codebase and the attached example from matthies.
My Java version is OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.10.2-b13), but I am targeting 1.6 via Maven.
It is not an issue in Netbeans 8.1, netbeans-trunk-nightly-201701300002-javase-linux, or when 1.8 is targeted.
Comment 7 md_5 2017-02-01 05:54:20 UTC
Ok so I did some more digging on this and it's actually Javac emitting these warnings when to DiagnosticListenerImpl when -source is not 1.8 (only changing that option via code). Not sure why it's not doing this in 8.1 though. Is netbeans packaging it's own
Comment 8 md_5 2017-02-01 06:42:19 UTC
I see that there is indeed nb-javac.
Not sure I'm skilled enough to drill down and find where the issue was introduced there however - hg merges confuse me.
Comment 9 Tomas Hurka 2017-02-17 07:24:01 UTC
JDK bug is fixed and the fix is already in nb-javac The problem is fixed in current dev. build of NetBeans.
Comment 10 md_5 2017-02-17 07:34:40 UTC
Thanks for the link Tomas.

I realise it is currently fixed in nightly, however I am requesting that this fix please be backported and released as it makes Netbeans 8.2 essentially unusable for development with source < 8.
Comment 11 Dusan Balek 2017-05-02 14:20:26 UTC
Unfortunately, the recent changes to nb-javac (e.g. jdk9 modules support) prevent us from safely backporting any non trivial changes from dev to NB 8.2. Please use the current NB Development Build.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo