Compiler bug with generics and private inner classes

There appears to be a bug in the sun java compiler. This problem was reported against eclipse and the developers their concluded that it must be a problem with javac.
Idea also seems to compile the example below. I couldn't find a bug report in the sun bug database. Can somebody tell me if this is a bug in javac and if there is a bug report for it.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422
public class Foo <T>{
private T myT;
public T getT() {
return myT;
public void setT(T aT) {
myT = aT;
public class Bar extends Foo<Bar.Baz> {
public static void main(String[] args) {
Bar myBar = new Bar();
myBar.setT(new Baz());
System.out.println(myBar.getT().toString());
private static class Baz {
@Override
public String toString() {
return "Baz";
Eclipse compiles and runs the code even though the Baz inner class is private.
javac reports:
Bar.java:1: Bar.Baz has private access in Bar
public class Bar extends Foo<Bar.Baz>
^
1 error

As I said in my original post its not just eclipse that thinks the code snippet is compilable. IntelliJ Idea also parses it without complaining. I haven't looked at the java language spec but intuitively I see no reason why the code should not compile. I don't think eclipse submitting bug reports to sun has anything to do with courage. I would guess they just couldn't be bothered.

Similar Messages

  • Private inner class and static private inner

    Hi,
    I understand the concept and usage of inner classes in general.
    When should we go for a private inner class and when for a static private inner class? I tried searching but it wasn't of much help.
    Basically I need to design a caching solution in which I need to timestamp the data object. After timestamping, data will be stored in a HashMap or some other collection. I'm planning to use a wrapper class (which is inner and private) which holds the data object and timestamp. I can make the program work by using either normal inner class or static inner class, however would like to know which is better in such case. Also If I can get some general guidelines as to when to use a staic inner class and when to use a normal inner class, it would help me.
    Thanks in advance.

    user1995721 wrote:
    When should we go for a private inner class and when for a static private inner class?
    I can make the program work by using either normal inner class or static inner class, however would like to know which is better
    If I can get some general guidelines as to when to use a static inner class and when to use a normal inner class, it would help me.Making the inner class static is helpful in that it limits visibility.
    If the inner class needs to access non-static fields or methods from the containing class instance
    the inner class has to be non-static.

  • Creating Private Inner Classes in Separate Files

    I sometimes find myself wanting to use private inner classes to do things, but then moving the classes to separate files and giving them package access just because I don't like having single large files.
    Is there a way to create private inner classes on a class but just save them in another file?
    Thanks,
    John

    For me, short file sizes usually make design structure
    more clear. This can make maintenance easier. It can
    also make browsing the code easier, even if you have a
    good editor or IDE. It is also less intimadating
    psychologically (for me, anyway) to work with a number
    of small files, each one with a distinct purpose, than
    it is to open up a monster, even if the monster does
    represent a coherent design unit in some sense. I
    think this psychological impact may be more important
    than most people give it credit for.The psychological impact is lessened if you use an IDE like VisualAge (where only one method at a time is generally displayed) or use the "Show Source Of Selected Element Only" option in Eclipse.
    It's one thing to say a method should be short and a class should have as few methods as possible. Those forces reduce complexity and ease maintenance. It's another to say a source file should be short. A source file is just a storage artifact; source code could be stored in a database without changing how the programmer interacts with it. The fact that the standard java compiler requires the implementation of nested classes to be stored inside the source file of their containing class is a minor inconvenience. Don't let it discourage you from using inner classes when they make sense. The design should not be driven by source file size considerations.
    >
    But you have added code only with the sole intent of
    making a source file smaller. If Java had amechanism
    for storing nested classes in other files youwouldn't
    do this. My point below was that you shouldn't let
    source file size override the decision to use anested
    class.Why shouldn't I let it? There are plenty of
    non-trivial benefits (the ones I gave above, for
    starters) to working with smaller files.Because all of those benefits can be gained from using a decent IDE. Eclipse is free. It can show only the current method and it can collapse nested classes.
    You say "If
    Java had a mechanism...." Well, I could answer: It
    does have such a mechanism, and that mechanism is
    packages.Packages are not a mechanism for creating private inner classes in separate files. Eclipse has a mechanism for making the fact that they reside in the same source file a non-issue.
    >>
    I am not being cavalier. I have no argument, onlyan
    opinion.Again, you are perfectly entitled to your opinion.
    But if it is truly an opinion, and nothing more, why
    bother telling me about it. You might as well post
    your favorite color. It is the reasons for your
    opinion that interest me, and you still have not
    really given any.I have had lengthy arguments about the issue of method and class size. Like I said before, I prefer very small classes and methods. I also think the number of nested classes should be as small as possible. But I have no problem with large files. Files are just one way to organize source code. The size of the things in the files matters, not the files themselves.

  • Private inner class

    I have a private inner class , the methods and constructor of this inner class should be private or default ?Please explain me what is the right method and constructor access modifier I should use to private inner classes .

    paulcw wrote:
    I believe that if you make the constructor private, nothing can instantiate it.Not true for an inner class.
    Re the original question: I'm not sure it really matters here, but I've not seen a canonical answer to this.

  • I just updated my Firefox browser to Firefox 8. I am a college student and practice with HTML and CSS for class assignments. The fonts in all my html documents are being overwritten online by your script typeface. How do I resolve this issue?

    I just updated my Firefox browser to Firefox 8. I am a college student and practice with HTML and CSS for class assignments. The fonts in all my html documents are being overwritten online by your script typeface. I did not have this issue in the older version. I use an iMAC running OS10.6.8. How do I resolve this issue?

    Starting with this, you have errors in your CSS code.
    body {
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
      margin-left: 0px;
      color: 151515;
      font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
      background-color: EFF5F8;
    body {
      margin:0;
      color: #151515;
      font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
      background-color: #EFF5F8;
      font-size: 100%;
    Related links:
    Windows Chrome, why do my fonts look so bad? - Lee Green
    css3 - Bad font rendering Chrome - Stack Overflow
    Nancy O.

  • BUG: Oracle Java Compiler bug with anonymous inner classes in constructor

    The following code compiles and runs just fine using 1.4.2_07, 1.5.0_07 and 1.6.0_beta2 when compiling and running from the command-line.
    It does not run when compiling from JDeveloper 10.1.3.36.73 (which uses the ojc.jar).
    When compiled from JDeveloper, the JRE (both the embedded one or the external 1.5.0_07 one) reports the following error:
    java.lang.VerifyError: (class: com/ids/arithmeticexpr/Scanner, method: <init> signature: (Ljava/io/Reader;)V) Expecting to find object/array on
    stack
    Here's the code:
    /** lexical analyzer for arithmetic expressions.
    Fixes the lookahead problem for TT_EOL.
    public class Scanner extends StreamTokenizer
    /** kludge: pushes an anonymous Reader which inserts
    a space after each newline.
    public Scanner( Reader r )
    super( new FilterReader( new BufferedReader( r ) )
    protected boolean addSpace; // kludge to add space after \n
    public int read() throws IOException
    int ch = addSpace ? ' ' : in.read();
    addSpace = ch == '\n';
    return ch;
    public static void main( String[] args )
    Scanner scanner = new Scanner( new StringReader("1+2") ); // !!!
    Removing the (implicit) reference to 'this' in the call to super() by passing an instance of a static inner class 'Kludge' instead of the anonymous subclass of FilterReader fixes the error. The code will then run even when compiled with ojc. There seems to be a bug in ojc concerning references to the partially constructed object (a bug which which is not present in the reference compilers.)
    -- Sebastian

    Thanks Sebastian, I filed a bug for OJC, and I'll look at the Javac bug. Either way, OJC should either give an error or create correct code.
    Keimpe Bronkhorst
    JDev Team

  • Private inner class with private constructor

    I read that if constructor is public then you need a static method to create the object of that class.
    But in the following scenario why I am able to get the object of PrivateStuff whereas it has private constructor.
    I am messing with this concept.
    public class Test {
          public static void main(String[] args) {          
               Test t = new Test();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }

    A member (class, interface, field, or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:
    * Otherwise, if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.1]
    Your main method is within the body of the top level class, so the type (the inner class) and method are accessible.
    eg:
    class ImInTheSameSourceFileAsInnerAccessTest {
        public static void main(String[] args) {          
            InnerAccessTest t = new InnerAccessTest();
            InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    public class InnerAccessTest {
          public static void main(String[] args) {          
               InnerAccessTest t = new InnerAccessTest();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }Result:
    $ javac -d bin src/InnerAccessTest.java
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    2 errors
    Edited by: pm_kirkham on 20-Jan-2009 10:54 added example of 'in the same source file'

  • Private inner classes

    I'm trying to complete a "turn the lightbulb on and off" program, but when I try to draw circle2 in the
    ButtonListener class I get an error message cannot find symbol. This is in reference to the Graphics
    variable "page" created in the paintComponent method below. Shouldn't the inner class, private or
    public inherit all data variables including objects from the parent class, in this case, the Bulb class? The code is below.
    By the way, this IS NOT a school assignment so any help would be appreciated. I'm just trying to learn
    this language.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Bulb extends JPanel
         private JButton push;
         private Circle circle, circle2;
         private final int DIAMETER = 100;
         private final int X = 10;
         private final int Y = 10;
         public Bulb()
              circle = new Circle(DIAMETER, Color.white, X,Y);
              circle2 = new Circle(DIAMETER, Color.yellow, X, Y); // to separate class
              push = new JButton("Turn on the Bulb");
              push.addActionListener(new ButtonListener());
              add(push);
              setPreferredSize(new Dimension(500, 500));
              setBackground(Color.black);
         public void paintComponent(Graphics page)
              super.paintComponent(page);
              circle.draw(page);
    private class ButtonListener implements ActionListener
              public void actionPerformed(ActionEvent event) //PROBLEM AREA. I GET ERROR MESSAGE STATING
    // "CANNOT FIND SYMBOL" IN REFERENCE TO VARIABLE "PAGE."
    // I THOUGHT THE INNER CLASS INHERITS ALL DATA FROM
    // PARENT CLASS SUCH AS "PAGE."
                   circle2.draw(page);
    }

    There are fields, which are associated with either a class or an object (and thus live in the heap in an object on the heap), and there are local variables, which are associated with methods and threads (i.e., a method invoked within a thread, and which thus live on the stack).
    They're not the same thing.
    You can't use a local variable in your paintComponent method in a different method.
    Anyway you're designing your class wrong. Think model-view-controller. You have the model: a bunch of state and possibly behavior that represents the thing being seen, modified, and displayed. You have the view, which is how you see the model. And you have the controller, which modifies the model.
    Your event handlers are part of the controller. They should change the model.
    Your paintComponent method is part of the view.
    So the event handlers should change some data, e.g., add a note that a circle should be displayed.
    Then your paintComponent method should look at the data and act accordingly -- e.g., see that there's a circle to be displayed, and display it.

  • SDK 3.0: Compiler bug with std::deque?

    When I call std::deque::assign(), I get all kinds of compile-time errors, including internal compiler errors.
    Note, however, that this happens only when I compile for the 3.0 device. It does not happen when I compile for the 3.0 simulator, 2.x device or 2.x simulator. In all those other modes it compiles and works just fine. Only when compiling for the 3.0 device, the compiler errors happen.
    I'm pretty certain this is a bug in the SDK. Has anyone else noticed this?

    Assign is a particularly tricky one. There are two assign methods. One takes two iterators and the other takes a size and value:
    template<class InputIterator>
    void assign(InputIterator first, InputIterator last);
    void assign(size_type n, const T & t);
    For whatever reason, the compiler for the 3.0 device is saying "int" and "int *" are the same type. It is instantiation the version with the iterators instead of the second one. This is a typical error you might see on a platform with weak C++ support. I used to have to deal with things like this all the time in the early days of MacOS X.
    Unfortunately, the only workaround is to do something else. The following should work:
    #include <algorithm>
    std::deque<int> values;
    std::filln(std::backinserter(values), 10, 1);

  • Problems with getWidth() and getHeight() in class Canvas

    Hi,
    i am developing MIDlets with Sun Studio4 One Update1 (Mobile Edition). Here is a simple example Code for my Problem:
    class MyCanvas extends Canvas
        public void paint(Graphics g)
            //Clear the Display
            g.setColor(0,0,0); //black
            g.fillRect(0,0,getWidth(),getHeight());
    }If i try to execute the Program with the Default Color Phone emulator included with Suns WTK2.0, everything works fine. (Ive tried to print out the results of getWidth() and getHeight() on the console, everything ok, the Displays width and height is displayed.).
    The problem is, that any other emulator from WTK1.0.4_01 (included with Sun Studio4 ME) compiles and preverifies fine, but while running the application, the emulator quits with the following error:
    ALERT: No such method getWidth.()I
    Execution completed successfully
    Anyone has an idea?
    Thanks!!

    Hello,
    I'm having the exact same problem and I'd like to know what changes you made to your code to get it working. My class is not an inner class and is very much like yours and so follows the form:
    class MyCanvas extends Canvas{ 
    int element = getWidth()/10;
    public void paint(Graphics g) {        //Clear the Display  
    g.setColor(0,0,0); //black
    g.fillRect(0,0,getWidth(),getHeight());
    I am also using WTK104. I did not have this problem until I renamed my file. I carried the renaming throughout the rest of the file in a consistent fashion and I don't see any problems with it. Any help appreciated.

  • How to deal with conflict and potential conflict classes?

    Some classes are marked as conflict and potential conflict classes in the Classloader Analysis Tool.
    How to deal with them?
    How to use suggested solutions?

    Not double load them.
    Conflicting classes can lead to weird exceptions. One obvious example would be if you package
    an older servlet.jar version into your application and use the weblogic classloading features, such
    as prefer-web-inf-classes, to tell weblogic to use this class instead of the one provided in the
    system classpath. This one example which leads to weird exceptions, such as connot process jsp tag...
    If you really need a the version of the jar for your application, you have to test it through and through
    so that you know you do not run into weird production errors.

  • Strange bug with the java.io.File class

    Hi everibody!
    I'm writting a system to upload images with JSF and RichFaces. But when i try to delete the images files sometimes hapen some strange bug.
    first i'll post my method code here:
    public void deleteUploadedFile(ActionEvent event) throws Throwable {
            UIComponent link = event.getComponent();
            UIParameter param = (UIParameter) link.findComponent("fileId");
            TheFile file = this.uploadedFiles.get((Integer) param.getValue());
            try {
                File f = new File(file.getPath(), file.getName());
                if ((f.exists()) && (f.canRead()) && (f.canWrite())) {
                    if(f.delete()){
                        for(int i=0; i<file.getThumbs().size(); i++){
                            File t1 = new File(file.getPath(), file.getThumbs().get(i).getThumbName());
                            t1.delete();
                        setDeleted(true);
                    else{
                        setDeleteLog("Arquivo não pode ser excluido");
                        setDeleted(false);
                } else {
                    setDeleteLog("Erro ao tentar excluir o arquivo");
                    setDeleted(false);
                this.finalize();
            } catch (Exception ex) {
                setDeleteLog("Deu erro: " + ex);
            } finally {
                if (this.deleted) {
                    if (this.uploadedFiles.remove(file)) {
                        setDeleteLog("Conseguiu remover");
                    } else {
                        setDeleteLog("Deu erro");
        }Well, when the method run the f.delete() line, sometimes, something strange hapen. With is, the file data is deleted as expected, but the file it self is not deleted. And even when i run the line this.finalize the JVM still using the file, with don't allows me to try to delete it untill my tomcat stop (with kill the application that was using the file). And this don't hapen every time that i try to delete one file.
    And worse, once it hapen every next time that i try to delete one file hapen the same bug.
    My question is...what could it be, and what can i do to solve this?!

    About this is not a possible cause. Because before i upload a file I verify if the file already exists and even after i change the file name:
    //this method change the file name and eliminate all the special characters, and also attach the current day of month,
    //month, year, minute and second to the file name
    public String generateFileName(String fileName){
            Locale l = new Locale("pt","BR");
            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(TimeZone.getTimeZone("GMT-3").getID()), l);
            int ext = fileName.lastIndexOf('.');
            String name = fileName.replace(fileName.substring(ext), "");
            String newName = RemoverAcentos.remover(name).toLowerCase()+cal.get(cal.DAY_OF_MONTH)+cal.get(cal.MONTH)
                    +cal.get(cal.YEAR)+cal.get(cal.MINUTE)+cal.get(cal.SECOND)+fileName.substring(ext);
            return newName;
        }the upload method
    String fileName = generateFileName(item.getFileName());
            try {
                File uploadFile = new File(filepath, fileName);
                if (!uploadFile.exists()) {

  • Can anybody give me the table with tcode and its development class

    can anybody give me the table with tcode and its development class

    Hi phani,
    1) First retrieve program name from tstc table I.e field pgmna.
      2) Using pgmna retrieve from tadir table by using the following criteria from tadir table
       pgmid    = 'R3TR'
      AND object   = 'PROG'
      AND obj_name = tstc-pgmna.
    We will get development class or package in tadir i.e
    tadir-devclass 
    Thanks,
    Naveen Kumar.

  • Private inner classes, should this compile:

    class Outer
    &nbsp&nbsp&nbsp&nbspclass InnerA;
    &nbsp&nbsp&nbsp&nbspclass InnerB;
    &nbsp&nbsp&nbsp&nbspclass InnerA
    &nbsp&nbsp&nbsp&nbsp{
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspInnerB* m_inner;
    &nbsp&nbsp&nbsp&nbsp};
    &nbsp&nbsp&nbsp&nbspclass InnerB
    &nbsp&nbsp&nbsp&nbsp{
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspInnerA* m_inner;
    &nbsp&nbsp&nbsp&nbsp};
    The Sun Studio 8 C++ compiler says that InnerB is not accessible from InnerA and vica-versa.
    However, both classes are members of the outer class and I would think that just like member functions, they should have access to all the declarations (prviate or not) in the outer class.
    Is the compiler correct to complain about this?
    Kind Regards,
    Dave.

    the current wording of the standard favours the Sun' s interpretation.
    gcc have gone with assuming that core language defect report 45 will be accepted which would allow this.
    see http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45 .
    /lib

  • BUG: ojc compiler doesnt handle @Override on anonymous inner class methods

    Hi,
    jdev 10.1.3.3.0.4157, XP SP2, jdk 5 u13:
    for the following code sample:
    Object o = new Object()
        @Override
        public String toString2()
            return "some string";
    };With ojc set as a compiler (the default), ojc doesnt catch the error about overriding toString with toString2, changing the compiler to javac achieves the required and correct behavior.

    Thanks Frank, I logged a couple more not so serious issues a while back but didnt get any feedback on them. The subject of the posts didn't have a 'BUG' prefix though. Should I edit them so to give them some attention, or were they silently logged :) ?

Maybe you are looking for