vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Build/compilation issue with wildcard types

Open msohaill opened this issue 8 months ago • 2 comments

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.

msohaill avatar May 25 '25 18:05 msohaill

same as https://github.com/redhat-developer/vscode-java/issues/4053

anar-ibragimoff avatar May 27 '25 13:05 anar-ibragimoff

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

msohaill avatar May 27 '25 15:05 msohaill

Looks like this was resolved recently according to https://github.com/redhat-developer/vscode-java/issues/4053#issuecomment-2990424063 ? It may have been an upstream bug that was fixed there. @msohaill can you confirm if this is resolved in the pre-release stream ?

rgrunber avatar Jun 25 '25 20:06 rgrunber

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!

msohaill avatar Jun 25 '25 21:06 msohaill

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

[email protected]

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

davidhay1969 avatar Jul 02 '25 08:07 davidhay1969

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

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

[email protected]

alas the same problem 😿

davidhay1969 avatar Jul 02 '25 18:07 davidhay1969

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 https://github.com/redhat-developer/vscode-java/issues/3688 . This is looking like some kind of longer term limitation of ECJ compilation vs. Javac. See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1053, https://github.com/eclipse-jdt/eclipse.jdt.core/issues/366 .

rgrunber avatar Jul 03 '25 16:07 rgrunber