Lambda expression results in warning in Eclipse Lu

2019-04-11 06:43发布

问题:

I have a very similar problem as described in this unanswered question: Nested lambda expressions results in a warning in Eclipse Luna

I am using Eclipse Luna (Service Release 1, 4.4.1) with Windows 7 and Java 8 (jdk 1.8.0_05). The following (edited) code:

Collections.sort(new LinkedList<>(), (c1, c2) -> {
    return c1.equals(c2)? 1 : 0;
});

yields in a warning:

(Recovered) Internal inconsistency detected during lambda shape analysis

The warning is assigned to this part of the code: "(c1, c2) ->".

Note: interestingly, the shorter version omitting the return statement compiles fine without any warnings:

Collections.sort(new LinkedList<>(), (c1, c2) -> c1.equals(c2)? 1 : 0);

The same is true for this code where the types of c1 and c2 are given explicitly

Collections.sort(new LinkedList<>(), (Object c1, Object c2) -> {
    return c1.equals(c2)? 1 : 0;
});

What is going on here? (I don't believe that this bug suggestion: https://bugs.eclipse.org/bugs/show_bug.cgi?id=432110 (given in a comment of the related question) is of any help as there the warning occurrs in the context of an error.)

EDIT: The above code is a MWE, the original code that caused the problem looks like this:

    Collections.sort(list, (c1, c2) -> {
        Method m1 = this.allMethods.get(c1);
        Method m2 = this.allMethods.get(c2);

        int c = new Integer(m1.getParameterCount()).compareTo(
                new Integer(m2.getParameterCount()));

        if (c == 0) {
            Integer i1 = 0;
            Integer i2 = 0;
            if (ConstructorFactory.isTypeAcceptable(m1.getReturnType())) {
                i1 = 1;
            }
            if (ConstructorFactory.isTypeAcceptable(m2.getReturnType())) {
                i2 = 1;
            }

            c = i1.compareTo(i2);
        }

        if (c == 0) {
            c = m1.getName().compareTo(m2.getName());
        }

        return c;
    });

EDIT 2: Eclipse Kepler did NOT show this warning (same Java version).