Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Bugs in IntelliJ IDEA.

Thread view: 
£ukasz Krawczyk - 16 Nov 2006 09:10 GMT
Make a new Java project in IntelliJ Idea and add the following files. Try to
compile them.

1.
public class Test {

   // Variable name is the same as Class name!!!
   static String String;

   public static void main(String[] args) {
     System.out.println(String.valueOf('c'));
   }

}

2.
import java.util.ArrayList;

public class Test2 {
   ArrayList list = new <String>ArrayList<String>();
}

In the first example IntelliJ gives a warning: "Static member ... accessed
via instance reference", however Sun compiler doesn`t show anything.

In the second example Intellij doesn`t show anything, hovewer Sun`s compiler
points out a BUG.

I work on IntelliJ 5.1.2. Are these problems present in another IDE-s?
Are these true BUGS or is there something with my brain :D

Jujo
Daniel Dyer - 16 Nov 2006 09:43 GMT
> Make a new Java project in IntelliJ Idea and add the following files.  
> Try to
[quoted text clipped - 22 lines]
> accessed
> via instance reference", however Sun compiler doesn`t show anything.

This is exactly what I would expect to see.  The IDE has a lot of warnings  
that are not present in the compiler.  You can disable the inspections if  
you don't like them.  The reason you get a warning is because the "String"  
in the main method is the variable name, not the String class.  Calling a  
static method in this way is confusing and probably not what the  
programmer intended, hence the warning.  It's not wrong in the strictest  
sense, so the compiler doesn't complain.

> In the second example Intellij doesn`t show anything, hovewer Sun`s  
> compiler
> points out a BUG.

This one does look to be a bug in the IDE.  Have you tried one of the 6.0  
builds to see if it has been fixed?  Perhaps you should file a bug report.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

£ukasz Krawczyk - 16 Nov 2006 09:57 GMT
>> In the first example IntelliJ gives a warning: "Static member ...
>> accessed
[quoted text clipped - 7 lines]
> programmer intended, hence the warning.  It's not wrong in the strictest
> sense, so the compiler doesn't complain.

I agree, I didn`t realize that was the inspection, not compiler :)

But are You sure that this method is REALLY accessed, in this particular
case, via instance reference and NOT class name?
I can`t figure out the test to check this...
Even if String String = null, static methods of 'String' Class still can by
called, and not crash with an NullPointerException.

Jujo
Daniel Dyer - 16 Nov 2006 10:49 GMT
>>> In the first example IntelliJ gives a warning: "Static member ...
>>> accessed
[quoted text clipped - 17 lines]
> case, via instance reference and NOT class name?
> I can`t figure out the test to check this...

If you change the type of the variable called String to be Object:

    Object String = null;

The compilation will fail because there is no valueOf method in the Object  
class.

    String.valeOf('c'); // Fails to compile, "cannot find symbol".

> Even if String String = null, static methods of 'String' Class still can  
> by
> called, and not crash with an NullPointerException.

Doesn't matter, the field name is just used (instead of the class name) to  
qualify the static method name.  So this still works without a  
NullPointerException:

    public class Test
    {
       private String myString = null;

       public static void main(String[] args)
       {
           new Test().doStuff();
       }

       private void doStuff()
       {
           System.out.println(myString.valueOf(76));
       }
    }

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Daniel Dyer - 16 Nov 2006 23:35 GMT
>> 2.
>> import java.util.ArrayList;
>>
>> public class Test2 {
>>     ArrayList list = new <String>ArrayList<String>();
>> }

...

>> In the second example Intellij doesn`t show anything, hovewer Sun`s  
>> compiler
[quoted text clipped - 3 lines]
> 6.0 builds to see if it has been fixed?  Perhaps you should file a bug  
> report.

This is still an issue in IDEA 6.0.2.

Dan.

Signature

Daniel Dyer
http://www.uncommons.org

Daniel Pitts - 17 Nov 2006 00:04 GMT
> >> 2.
> >> import java.util.ArrayList;
[quoted text clipped - 20 lines]
> Daniel Dyer
> http://www.uncommons.org
It may be a bug, but it doesn't come up that often, does it?
Usually the generic type can be infered by the parameters, and AFAIK,
Idea handles this well enough, and its not really invalid syntax, so I
can understand why they missed it.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.