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

Bug 533644

Summary: JDK10: Incorrect Name clash error
Product: [Eclipse Project] JDT Reporter: Benjamin Manes <ben.manes>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, lgoldstein, manoj.palat, martin.keller, stephan.herrmann
Version: 4.7.3   
Target Milestone: 4.8 M7   
Hardware: PC   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/121535
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=235a3d96bce67e31626ffca69b9b34eaacd105d9
https://bugs.eclipse.org/bugs/show_bug.cgi?id=534471
Whiteboard:
Attachments:
Description Flags
sample project none

Description Benjamin Manes CLA 2018-04-16 20:27:29 EDT
A clash occurs when implementing a decorator for the org.quartz.Scheduler interface. The failure occurs with the following method:

void scheduleJobs(Map<JobDetail, Set<? extends Trigger>>, boolean) throws SchedulerException;

There is a similarly named method that might be causing confusion:

void scheduleJob(JobDetail jobDetail, Set<? extends Trigger> triggersForJob, boolean replace) throws SchedulerException;

The Gradle build passes and the application can run in Eclipse, but it does report the errors of:

Name clash: The method scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type RequestScopedScheduler has the same erasure as scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type Scheduler but does not override it	RequestScopedScheduler.java	/loaddocs/src/main/java/co/loaddocs/library/server/scheduler	line 155	Java Problem

The method scheduleJobs(java.util.Map<org.quartz.JobDetail,java.util.Set<? extends org.quartz.Trigger>>, boolean) in the type Scheduler is not applicable for the arguments (java.util.Map<org.quartz.JobDetail,java.util.Set<? extends org.quartz.Trigger>>, boolean)	RequestScopedScheduler.java	/loaddocs/src/main/java/co/loaddocs/library/server/scheduler	line 163	Java Problem

The method scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type RequestScopedScheduler must override or implement a supertype method	RequestScopedScheduler.java	/loaddocs/src/main/java/co/loaddocs/library/server/scheduler	line 155	Java Problem

The type RequestScopedScheduler must implement the inherited abstract method Scheduler.scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean)	RequestScopedScheduler.java	/loaddocs/src/main/java/co/loaddocs/library/server/scheduler	line 42	Java Problem
Comment 1 Manoj N Palat CLA 2018-04-16 23:54:24 EDT
Can you please attach a small reproducible test case?
Comment 2 Benjamin Manes CLA 2018-04-17 00:10:52 EDT
Created attachment 273637 [details]
sample project

This shows an error in Eclipse for me. No issue command-line.
Comment 3 Stephan Herrmann CLA 2018-04-17 09:18:43 EDT
(In reply to Benjamin Manes from comment #2)
> Created attachment 273637 [details]
> sample project
> 
> This shows an error in Eclipse for me. No issue command-line.

Thanks, these steps reproduce the bug without additional libraries / build tools:

1. Compile the following sources (e.g., in a separate project P1):

//---
package q;
import java.io.Serializable;
public interface JobDetail extends Serializable, Cloneable { }
//---
package q;
import java.util.Map;
import java.util.Set;
public interface Scheduler {
    void scheduleJobs(Map<JobDetail, Set<? extends Trigger>> triggersAndJobs, boolean replace) throws SchedulerException;
}
//---
package q;
public class SchedulerException extends Exception {
    private static final long serialVersionUID = 174841398690789156L;
}
//---
package q;
import java.io.Serializable;
public interface Trigger extends Serializable, Cloneable, Comparable<Trigger> {
    public static final long serialVersionUID = -3904243490805975570L;
}
//---

2. Then compile the following file against compiled .class from above (e.g., by creating a second project P2 that depends on P1):

//---
import java.util.Map;
import java.util.Set;

import q.JobDetail;
import q.Scheduler;
import q.SchedulerException;
import q.Trigger;

public class ForwardingScheduler implements Scheduler {
  @Override
  public void scheduleJobs(Map<JobDetail, Set<? extends Trigger>> triggersAndJobs, boolean replace)
      throws SchedulerException {
  }
}
//---

The left ruler will show these contradictory messages:

Multiple markers at this line
	- implements q.Scheduler.scheduleJobs
	- The method scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type ForwardingScheduler must override or implement a 
	 supertype method
	- Name clash: The method scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type ForwardingScheduler has the same erasure as 
	 scheduleJobs(Map<JobDetail,Set<? extends Trigger>>, boolean) of type Scheduler but does not override it


Putting all sources into the same project and performing Project Clean does not trigger the bug.
Comment 4 Stephan Herrmann CLA 2018-04-22 09:11:47 EDT
*** Bug 533348 has been marked as a duplicate of this bug. ***
Comment 5 Stephan Herrmann CLA 2018-04-22 09:14:27 EDT
(In reply to Stephan Herrmann from comment #4)
> *** Bug 533348 has been marked as a duplicate of this bug. ***

In that bug I found the problem to be introduced in 4.7.3 and 4.8M3.
Comment 6 Stephan Herrmann CLA 2018-04-22 10:30:02 EDT
(In reply to Stephan Herrmann from comment #5)
> (In reply to Stephan Herrmann from comment #4)
> > *** Bug 533348 has been marked as a duplicate of this bug. ***
> 
> In that bug I found the problem to be introduced in 4.7.3 and 4.8M3.

I had to un-duplicate the other bug, which happened without JDK10 and is already fixed, whereas here we definitely need JDK10 and don't yet have a fix.

Strange enough, I didn't succeed so far in creating a pure compiler JUnit, error is seen only in the IDE ...
Comment 7 Stephan Herrmann CLA 2018-04-22 15:31:18 EDT
Debugging the IDE I observed:

We don't detect the override, because the wildcard in the signature ("? extends Trigger") has duplicate representations in TypeSystem.types.

Duplicate wildcard representations seem to be caused by duplicate representations of java.util.Set as UnresolvedReferenceBinding (which cause us to search in the wrong derivedTypes slot).

This in turn seems to be caused by bogus lookup via split package java.util from java.base, java.logging, java.prefs. Those packages exist indeed, but don't contain any types (types are in java.util.logging and java.util.prefs).
Comment 8 Eclipse Genie CLA 2018-04-22 17:33:07 EDT
New Gerrit change created: https://git.eclipse.org/r/121535
Comment 9 Stephan Herrmann CLA 2018-04-22 18:05:55 EDT
(In reply to Eclipse Genie from comment #8)
> New Gerrit change created: https://git.eclipse.org/r/121535

Test needs to use module mode to trigger the problem. Not sure what impact JDK 10 had nor why this issue didn't occur before.

The root cause could be found where the URB is created in the first place: we must not place the URB into a SplitPackageBinding otherwise it will not be found by subsequent lookup. Checking which incarnation has CUs resolves the problem - given that no illegal package split (accessible from more than one module) exists.
Comment 11 Stephan Herrmann CLA 2018-04-22 18:49:18 EDT
(In reply to Eclipse Genie from comment #10)
> Gerrit change https://git.eclipse.org/r/121535 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=235a3d96bce67e31626ffca69b9b34eaacd105d9

Released for 4.8 M7.
Comment 12 Benjamin Manes CLA 2018-04-22 18:50:12 EDT
Thank you!
Comment 13 Jay Arthanareeswaran CLA 2018-05-10 12:32:08 EDT
Verified for 4.8 M7 with build I20180509-2000
Comment 14 Stephan Herrmann CLA 2018-05-14 17:23:56 EDT
*** Bug 534471 has been marked as a duplicate of this bug. ***