Bug 547870 - The AST parser could not parse proper code (Error: Type mismatch: cannot convert from ... to ...)
Summary: The AST parser could not parse proper code (Error: Type mismatch: cannot conv...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.12   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-03 08:14 EDT by Wojciech Andrijew CLA
Modified: 2023-06-06 05:20 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wojciech Andrijew CLA 2019-06-03 08:14:27 EDT
The Jenkins project contains below code:

    /**
     * Stores manually registered Descriptor instances. Keyed by the {@link Describable} type.
     */
    @SuppressWarnings("rawtypes")
    private static final Map<Class, CopyOnWriteArrayList<ExtensionComponent<Descriptor>>> legacyDescriptors = new ConcurrentHashMap<>();

    @SuppressWarnings({"unchecked", "rawtypes"})
    private static <T extends Describable<T>> CopyOnWriteArrayList<ExtensionComponent<Descriptor<T>>> getLegacyDescriptors(Class<T> type) {
        return legacyDescriptors.computeIfAbsent(type, key -> new CopyOnWriteArrayList());
    }

Above code is parsed by Java 8 / 11 compiler without any problem.

But AST parser returns error:

Type mismatch: cannot convert from CopyOnWriteArrayList<ExtensionComponent<Descriptor>> to CopyOnWriteArrayList<ExtensionComponent<Descriptor<T>>>

How to reproduce:
1. Download source of Jenkins project
https://codeload.github.com/jenkinsci/jenkins/zip/master
2. Unpack and import core project into Eclipse
3. Go to jenkins-master\core\src\main\java\hudson\CopyOnWrite.java

Error appears on 227 line number.
Comment 1 Stephan Herrmann CLA 2019-06-03 17:26:20 EDT
Seeing that the code extensively uses rawtypes, it has no priority for me personally (other team members may still have other views), because:

- rawtypes were invented for the sole purpose for migrating from Java 1.4 to 5. I'm not aware of a valid excuse for writing/maintaining code like "new CopyOnWriteArrayList()" still in 2019. This basically indicates that you are not interested in type safety. If that's the case remove type arguments consistently. Combining the sophisticated type inference of Java 8 with rawtypes is broken by design.

- javac is known to have bugs in this area, where it confuses equality and compatibility of type arguments. So even *if* I'd start investigation we wouldn't know if there's a bug in ecj to begin with.

sorry
Comment 2 Eclipse Genie CLA 2021-05-24 12:09:30 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Eclipse Genie CLA 2023-06-06 05:20:01 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.