Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 236370

Summary: [compiler][1.5] compiler difference to javac 7 involving raw static call
Product: [Eclipse Project] JDT Reporter: Maxime Daniel <maxime_daniel>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: kent_johnson, philippe_mulet, stephan.herrmann
Version: 3.4   
Target Milestone: 4.16 M3   
Hardware: PC   
OS: All   
Whiteboard:

Description Maxime Daniel CLA 2008-06-10 02:58:47 EDT
I20080604-2000

On the following code (which is GenericTypeTest#1034), jdk 7 b24 departs from Eclipse by not complaining on the line marked 1:
interface Closure<I> {
    public void execute(I input);
}

class ChainedClosure<I> implements Closure<I> {
    private final Closure<? super I>[] iClosures;
    @SuppressWarnings("unchecked")
    public static <I> Closure<I> getInstance(Closure<? super I> closure1, Closure<? super I> closure2) {
        if (closure1 == null || closure2 == null) {
            throw new IllegalArgumentException("Closures must not be null");
        }
        Closure<I>[] closures = new Closure[] { closure1, closure2 };
        return new ChainedClosure<I>(closures);
    }
    public ChainedClosure(Closure<? super I>[] closures) {
        super();
        iClosures = closures;
    }
    public void execute(I input) {
        for (int i = 0; i < iClosures.length; i++) {
            iClosures[i].execute(input);
        }
    }
}
class ClosureUtils {
    public static <J> Closure<J> chainedClosure(Closure<? super J> closure1, Closure<? super J> closure2) {
        return ChainedClosure.getInstance(closure1, closure2);
    }
    public static Closure<String> chainedClosure2(Closure<? super String> closure1, Closure<? super String> closure2) {
        return ChainedClosure.getInstance(closure1, closure2);
    }
    public static <J> Closure<String> chainedClosure3(Closure<? super J> closure1, Closure<? super J> closure2) {
        return ChainedClosure.getInstance(closure1, closure2); // 1
    }
}

This may either be a javac bug, or else denote a move to more permissive a treatment of raw types (as keeping some characteristics of fully parameterized types) - ChainedClosure here.
Comment 1 Philipe Mulet CLA 2008-06-16 07:20:56 EDT
Test GenericTypeTest#test1034 corresponds to bug 158519, which itself refers to javac bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954 
Comment 2 Maxime Daniel CLA 2008-06-18 03:41:21 EDT
This bug watches a divergence, not a convergence. More precisely, javac 7 converges with us on test765 and departs from us on test1034.
Comment 3 Philipe Mulet CLA 2008-06-18 06:19:46 EDT
I agree this is strange that they would still deviate on test1034 when they now agree with us on test765.

Will ask for clarification to spec master.
Comment 4 Kent Johnson CLA 2009-03-19 16:31:13 EDT
    public static Closure<Integer> chainedClosure4(Closure<? super String> closure1, Closure<? super String> closure2) {
        return ChainedClosure.getInstance(closure1, closure2);
    }

javac also doesn't complain about this case

the return type doesn't appear to influence the inferred type
Comment 5 Kent Johnson CLA 2009-03-20 11:42:08 EDT
Some other cases where we differ from javac. Sure looks like javac has a bug since they seem to ignore the return type in 3 cases.

class A<T> {
	static <U> A<U> x(A<? super U> a1, A<U> a2) { return a2; }
	static <U> A<U> y(A<U> a1, A<? super U> a2) { return a1; }
	static <U> A<U> z(A<? super U> a1) { return null; }
}

class X {
	// we agree on these 3 cases when one parameter is not a capture
	<J> A<String> x1(A<? super J> a1, A<J> a2) {
		return A.x(a1, a2); // incompatible return types
	}
	<J> A<String> x2(A<? super J> a1, A<? extends J> a2) {
		return A.x(a1, a2); // incompatible return types
	}
	<J> A<String> y1(A<J> a1, A<? super J> a2) {
		return A.y(a1, a2); // incompatible return types
	}

	// eclipse detects errors in these 3 cases which javac does not
	<J> A<String> z1(A<? super J> a1) {
		return A.z(a1); // no error from javac
	}
	<J> A<String> z2(A<? extends J> a1) {
		return A.z(a1); // no error from javac
	}
	A<String> z3(A<Number> a1) {
		return A.z(a1); // no error from javac
	}
}
Comment 6 Eclipse Genie CLA 2020-05-11 17:11:11 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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 7 Stephan Herrmann CLA 2020-05-12 07:30:43 EDT
this was a javac bug fixed in or before 1.7.0_80

to wit: GTT.test1034 passes in https://ci.eclipse.org/jdt/job/eclipse.jdt.core-run.javac-1.8