Bug 142772 - [1.5][compiler] Compilation succeeds with static imports that fail with javac
Summary: [1.5][compiler] Compilation succeeds with static imports that fail with javac
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-19 10:59 EDT by Ricky Clarkson CLA
Modified: 2006-09-12 08:34 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ricky Clarkson CLA 2006-05-19 10:59:27 EDT
The following code compiles fine with Eclipse:

package test;
 
public class One
{
        public static void arrayList()
        {
        }
}
 
Separate file:
 
package test;
 
import static test.One.arrayList;
 
class Two
{
        public static void arrayList(int x)
        {
                arrayList();
        }
}

With javac, it reports:

$ javac test/*.java
test/testcase.java:9: arrayList(int) in test.Two cannot be applied to ()
                arrayList();
                ^

While I prefer the Eclipse behaviour, I'd like to retain source compatibility with Java.

Testers report that RC4 and RC5 exhibit this behaviour - I experienced it myself with 3.2M5.
Comment 1 Ricky Clarkson CLA 2006-05-19 11:02:46 EDT
I meant RC3 and 4, as 5 isn't actually available at the time of submitting this bug.  I misread sarcasm on the part of the tester!
Comment 2 Ricky Clarkson CLA 2006-05-19 11:23:06 EDT
This bug has already been reported against javac, and closed because the specification says it's the correct behaviour.  I cannot find where that is true in the Java Language Specification.

The relevant bug report is here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5085373
Comment 3 Philipe Mulet CLA 2006-05-19 11:45:57 EDT
Thanks for the report
Comment 4 Philipe Mulet CLA 2006-05-22 05:08:45 EDT
From JLS spec team:
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.1

        "A declaration d of a method named n shadows the declarations of
        any other methods named n that are in an enclosing scope at the
        point where d occurs throughout the scope of d."

This means that the declaration of arrayList(int) shadows the one that
is imported.
Comment 5 Kent Johnson CLA 2006-05-31 15:58:36 EDT
Added StaticImport test45

Released change to Scope.getImplicitMethod into 3.2.1 branch
Comment 6 Frederic Fusier CLA 2006-06-12 06:15:19 EDT
Released for 3.2.1
Released for 3.3 M1 while merging TARGET_321 in HEAD
Comment 7 Stephen Kestle CLA 2006-07-18 23:27:32 EDT
I believe this is not fixed:  

package test;
public class One{
    public static void arrayList(String s){}
}

Separate file:

package test;
class Two{
    public void arrayList(int x){}
}

Separate file:

package test;
import static test.One.arrayList;
class Three extends Two{
   public static void aMethod(){
       arrayList("s");  //Compiles fine under eclipse, but not javac
   }
}
Comment 8 Ricky Clarkson CLA 2006-07-19 07:31:06 EDT
I reproduced Stephen Kestle's results, and am therefore reopening this bug.
Comment 9 Kent Johnson CLA 2006-07-19 10:37:16 EDT
Which build are you using?

I tried this with the latest from HEAD and the 3.2.1 branch, and they both report the same error as javac.
Comment 10 Kent Johnson CLA 2006-07-19 10:42:40 EDT
Added additional cases as StaticImport test45b
Comment 11 Stephen Kestle CLA 2006-07-20 17:18:29 EDT
My build id is  M20060629-1905, and the core jdt 3.2.1.z20060711-1626.

Kent, just in case you missed it, the problem was that the static import of class Three was being shadowed by the method in the super-class Two.
Comment 12 Frederic Fusier CLA 2006-08-07 11:03:18 EDT
Verified for 3.3 M1 using build I20060807-0010.
Comment 13 Frederic Fusier CLA 2006-09-12 08:34:12 EDT
Verified for 3.2.1 using build M20060908-1655.

Note that Three.java comment 7 test case does not compile in Eclipse neither in 3.2 nor in 3.2.1...