Skip to content

Build/compilation issue with wildcard types #4059

Open

Description

@msohaill

Following is some sample code to replicate the issue:

import java.util.List;

public class Tester {
    <T extends List<? extends Entry<?, ?>>> Entry<?, ?> test(T input) {
        return ConcreteEntry.from(input.get(0));  // Error here
    }

    public static void main(String[] args) {
        Tester tester = new Tester();

        System.out.println(tester.test(List.of(new ConcreteEntry<>("a", 1))));
    }

}

interface Entry<K, V> {
    K getKey();

    V getValue();
}

class ConcreteEntry<K, V> implements Entry<K, V> {
    private final K key;
    private final V value;

    public ConcreteEntry(K key, V value) {
        this.key = key;
        this.value = value;
    }

    public static <K, V> ConcreteEntry<K, V> from(Entry<K, V> entry) {
        return new ConcreteEntry<>(entry.getKey(), entry.getValue());
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public String toString() {
        return this.key + "=" + this.value;
    }
}

The test method throws the error The method from(Entry<K,V>) in the type ConcreteEntry is not applicable for the arguments (capture#1-of ? extends Entry<?,?>) Java(67108979). The expected behaviour is correct compilation. However, enabling the "java.jdt.ls.javac.enabled" works, but is not an ideal solution.

This occurs with the latest Language Support for Java(TM) by Red Hat - v1.42.0.

Activity

  1. anar-ibragimoff commented on May 27, 2025

    @anar-ibragimoff

    same as #4053

  2. msohaill commented on May 27, 2025

    @msohaill
    Author

    same as #4053

    Strangely enough, I still get the issue when downgrading to v1.41.1. Perhaps it is an issue with the Eclipse Language Tools? Not sure if there's a pinned version or anything

  3. rgrunber commented on Jun 25, 2025

    @rgrunber
    Member

    Looks like this was resolved recently according to #4053 (comment) ? It may have been an upstream bug that was fixed there. @msohaill can you confirm if this is resolved in the pre-release stream ?

  4. msohaill commented on Jun 25, 2025

    @msohaill
    Author

    Hi @rgrunber! It seems I still get the issue with v1.43.2025062508. The error message remains the same. Let me know if you would require any more information!

  5. davidhay1969 commented on Jul 2, 2025

    @davidhay1969

    Morning, also seeing a similar issue with versions of the extension post v1.41.1 including the current latest pre-release version: -

    redhat.java@1.44.2025062800
    

    Looking thorugh the linked issues / PRs, to check whether there's anything else about my environment ( macOS, VSCode, JDK etc. ) that's relevant ...

  6. davidhay1969 commented on Jul 2, 2025

    @davidhay1969

    Just got a new update on the pre-release channel: -

    code --list-extensions --show-versions | grep redhat.java

    redhat.java@1.44.2025070208
    

    alas the same problem 😿

  7. rgrunber commented on Jul 3, 2025

    @rgrunber
    Member

    I tried with 1.32.0 and still see the errors there as well, so likely this isn't something to recently regress. Seems similar to #3688 . This is looking like some kind of longer term limitation of ECJ compilation vs. Javac. See eclipse-jdt/eclipse.jdt.core#1053, eclipse-jdt/eclipse.jdt.core#366 .

  8. interrupt-routine commented on Jan 29, 2026

    @interrupt-routine

    As of v1.52.0 I hit the same bug with code samples as simple as this:

    import java.util.*;
    
    public class Main {
        void wildcard(List<?> x) {
            List<List<Object>> y = x.stream().map(List::of).toList();
        }
    }

    Type mismatch: cannot convert from List<List<capture#1-of ?>> to List<List<Object>>Java(16777233)

    Compiles fine with javac -Xlint:all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions