JDK-8064866 : incorrect compiler warning "potentially ambiguous"
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u25
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-11-04
  • Updated: 2015-06-10
  • Resolved: 2015-06-10
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Windows 7 Ultimate 64bit

EXTRA RELEVANT SYSTEM CONFIGURATION :
This is a compiler issue new to 1.8.0_25. The code compiled fine with the previous version. The previous version directory was 1.7.0_25 although later versions had been installed.

A DESCRIPTION OF THE PROBLEM :
when compiling code the compiler produces some incorrect warnings.

warnings of "potentially ambiguous" are produced on overloads that have different objects as arguments so there is no way it could be ambiguous.

I have yet to determine if any of these warnings cause the compiler to not compile any classes.

My project seems to run ok.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no warnings at all.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
.\com\a\event\EventMulticaster.java:46: warning: [overloads] add(ActionListener,ActionListener) in EventMulticaster is potentially ambiguous with add(SettingListener,SettingListener) in EventMulticaster
 public static ActionListener add(ActionListener _a,ActionListener _b)
                              ^
.\com\a\event\EventMulticaster.java:50: warning: [overloads] remove(ActionListener,ActionListener) in EventMulticaster is potentially ambiguous with remove(SettingListener,SettingListener) in EventMulticaster
 public static ActionListener remove(ActionListener _l,ActionListener _oldl)
                              ^
.\com\a\event\EventMulticaster.java:62: warning: [overloads] add(AtomListener,AtomListener) in EventMulticaster is potentially ambiguous with add(MouseWheelListener,MouseWheelListener) in EventMulticaster
 public static AtomListener add(AtomListener _a,AtomListener _b)
                            ^
.\com\arxary\event\EventMulticaster.java:66: warning: [overloads] remove(AtomListener,AtomListener) in EventMulticaster is potentially ambiguous with remove(MouseWheelListener,MouseWheelListener) in EventMulticaster
 public static AtomListener remove(AtomListener _l,AtomListener _oldl)
                            ^
4 warnings



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Listed are 2 listeners that are listed in the error message. I have about 20 listeners so I believe the compiler stopped upon the 2nd same error. 

CODE...

package com.a.event;
public interface AtomListener extends EventListener
 {
 public void atomCreated(AtomEvent _e);
 }

package com.a.event;
public interface SettingListener extends EventListener
 {
 public void settingApplied(SettingEvent _e);
 }



EXCERPT FROM EVENT MULTICASTER...

 public static ActionListener add(ActionListener _a,ActionListener _b)
  {
  return (ActionListener)addInternal(_a,_b);
  }
 public static ActionListener remove(ActionListener _l,ActionListener _oldl)
  {
  return (ActionListener)removeInternal(_l,_oldl);
  }
 public void actionPerformed(ActionEvent _e)
  {
  ((ActionListener)a).actionPerformed(_e);
  ((ActionListener)b).actionPerformed(_e);
  }
 public static AtomListener add(AtomListener _a,AtomListener _b)
  {
  return (AtomListener)addInternal(_a,_b);
  }
 public static AtomListener remove(AtomListener _l,AtomListener _oldl)
  {
  return (AtomListener)removeInternal(_l,_oldl);
  }
 public void atomCreated(AtomEvent _e)
  {
  ((AtomListener)a).atomCreated(_e);
  ((AtomListener)b).atomCreated(_e);
  }


as you can see the arguments for the overloads are completely different yet still raises a "potentially ambiguous" warning.

This code compiled fine without warnings before I upgraded to 1.8.0_25

The directory for my previous version was 1.7.0_25 although later updates had been installed.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
no workaround.


Comments
This is not a bug. The potentially ambiguous warning is there to flag situations in which the method might be considered ambiguous.The fact that in most case this is not a problem, doesn't mean that the potential ambiguity is not there - example: add(x->{}, y->{}); gives: Main.java:33: error: reference to add is ambiguous Test.add(x->{}, y->{}); ^ both method add(ActionListener,ActionListener) in Test and method add(AtomListener,AtomListener) in Test match 1 error
10-06-2015

Triage accordingly
05-06-2015

This looks like a possible duplicate of https://bugs.openjdk.java.net/browse/JDK-8038485. Submitting this for further review and at the same time have inquired submitter for a small test case.
14-11-2014