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

Bug 427478

Summary: [1.8][compiler] Wrong "Duplicate default methods" error on AbstractDoubleSpliterator
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: jarthana, srikanth_sankaran
Version: 4.4   
Target Milestone: BETA J8   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 427787    

Description Markus Keller CLA 2014-02-05 10:26:12 EST
When trying to compile rt.jar of Java 8 with ecj, I'm getting a compile error in java.util.Spliterators.AbstractDoubleSpliterator. I've extracted the problem into a self-contained example below.

I think the compile error is wrong because interface OfDouble already overrides the method Spliterator#forEachRemaining(Consumer<? super T>) with a concrete variant OfDouble#forEachRemaining(Consumer<? super Double>), so the former method should not be considered any more when AbstractDoubleSpliterator is compiled.

=====================================================================
package split2;

import java.util.function.Consumer;
import java.util.function.DoubleConsumer;

public interface Spliterator<T> {
    
    default void forEachRemaining(Consumer<? super T> action) {
    }
    
    public interface OfPrimitive<T, T_CONS, T_SPLITR extends OfPrimitive<T, T_CONS, T_SPLITR>>
            extends Spliterator<T> {
        // overloads Spliterator#forEachRemaining(Consumer<? super T>)
        default void forEachRemaining(T_CONS action) {
        }
    }
    
    public interface OfDouble extends OfPrimitive<Double, DoubleConsumer, OfDouble> {
        @Override // the method from Spliterator
        default void forEachRemaining(Consumer<? super Double> action) {
        }
        
        @Override // the method from OfPrimitive
        default void forEachRemaining(DoubleConsumer action) {
        }
    }
}

class Spliterators {
    /* Error on class: Duplicate default methods named forEachRemaining with
     * the parameters (Consumer<? super Double>) and (Consumer<? super T>) are
     * inherited from the types Spliterator.OfDouble and Spliterator<Double>
     */
    public abstract static class AbstractDoubleSpliterator implements Spliterator.OfDouble {

        /* Implementation that prevents the compile error: */
//        @Override // the method from Spliterator
//        public void forEachRemaining(Consumer<? super Double> action) {
//        }
    }
}
=====================================================================
Comment 1 Markus Keller CLA 2014-02-05 10:30:57 EST
I'm not blocked by this bug.
Comment 2 Srikanth Sankaran CLA 2014-02-11 19:32:09 EST
Disabled tests released here. Stephan, I heard from Jay that he is seeing in
quite a few files in the effort to build JRE8 using ECJ. Thanks for taking a
look.

in MV15.checkInheritedMethods, indices appear misaligned at first sight.
Comment 3 Srikanth Sankaran CLA 2014-02-11 19:33:03 EST
(In reply to Srikanth Sankaran from comment #2)
> Disabled tests released here.

Here: org.eclipse.jdt.core.tests.compiler.regression.InterfaceMethodsTest._test427478()
Comment 4 Srikanth Sankaran CLA 2014-02-12 04:51:18 EST
(In reply to Srikanth Sankaran from comment #2)

> in MV15.checkInheritedMethods, indices appear misaligned at first sight.

checkInheritedMethods(MethodBinding[] methods, int length, boolean[] isOverridden, boolean[] isInherited)

isOverridden and isInherited - indices seem to relative to original array of
inherited methods.

methods [] - a subset of matching methods collected into a fresh array. Indices
will not always match.

One possible solution is to identically aligned arrays that contain null
entries which need to be skipped over.
Comment 5 Srikanth Sankaran CLA 2014-02-13 00:14:25 EST
Now therefore, thus sayeth the Lord: The path of the righteous code is beset on
all sides by the misalignment of the arrays and the tyranny of incorrect index 
variables. Blessed is the method, who in the name of correctness and good practice, shepherds the contracts through the valley of verification, for he is 
truly his correctness's keeper and the finder of lost inheritance.

:)

Fix and tests released here: 

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=c9c353b1f3633c7934ab02e6b5f4d6f7b6d921d9
Comment 6 Jay Arthanareeswaran CLA 2014-02-21 05:26:14 EST
(In reply to Srikanth Sankaran from comment #5)
> Now therefore, thus sayeth the Lord: The path of the righteous code is beset
> on
> all sides by the misalignment of the arrays and the tyranny of incorrect
> index 
> variables. Blessed is the method, who in the name of correctness and good
> practice, shepherds the contracts through the valley of verification, for he
> is 
> truly his correctness's keeper and the finder of lost inheritance.

:-)

Verified for Java 8 RC1 using Kepler SR2 +  
Eclipse Java Development Tools Patch for Java 8 Support (BETA)   
1.0.0.v20140220-2054