Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guava can't be compiled by JDT #2082

Closed
GerardPaligot opened this issue Jun 17, 2015 · 2 comments
Closed

Guava can't be compiled by JDT #2082

GerardPaligot opened this issue Jun 17, 2015 · 2 comments

Comments

@GerardPaligot
Copy link

I'm a Spoon contributor, an open source project to analyse and transform Java source code. This project have a dependency to JDT to compile target source code. Recently, I tried to analyse Guava with Spoon but JDT can't compile our project.

What is the problem?

In ImmutableMap class, we have these methods:

// If the map is an EnumMap, it must have key type K for some <K extends Enum<K>>.
@SuppressWarnings({"unchecked", "rawtypes"})
private static <K, V> ImmutableMap<K, V> copyOfEnumMapUnsafe(Map<? extends K, ? extends V> map) {
    return copyOfEnumMap((EnumMap) map);
}

private static <K extends Enum<K>, V> ImmutableMap<K, V> copyOfEnumMap(EnumMap<K, ? extends V> original) {
    EnumMap<K, V> copy = new EnumMap<K, V>(original);
    for (Map.Entry<?, ?> entry : copy.entrySet()) {
        checkEntryNotNull(entry.getKey(), entry.getValue());
    }
    return ImmutableEnumMap.asImmutable(copy);
}

This code is valid but there is an error from JDT:

Type mismatch: cannot convert from <Enum<Enum<K>>> to <K>

Before the creation of this issue, I reported the bug in the bugtracker of JDT (issue here). In 2 words, the conclusion was that: "Yes, JDT don't support this usage of Java but there is a better practice". This better practice is explained here:

private static <K extends Enum<K>> ImmutableMap<K, V> copyOfEnumMap(EnumMap<K, ? extends V> original) {
    return copyOfEnumMap((EnumMap<K,?>) map);
}

I tried some tricky solutions but, unfortunately, this solution can't be applied in your project. So I come to notify you that your project can't be compiled by JDT.

@cpovirk
Copy link
Member

cpovirk commented Jun 17, 2015

I'm surprised that we haven't heard about this from internal Eclipse users. Thanks for pointing it out.

We might as well got off raw types where we can. I've found another approach that I'll submit shortly.

@eamonnmcmanus
Copy link
Member

It seems that the bug is new in the Eclipse compiler since the introduction of support for Java 8. I'm guessing internal users who might have looked at this code with Eclipse aren't on a version with that support yet.

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

No branches or pull requests

4 participants