Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4051281

Problem compiling when inner class references a private method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.1.5
    • 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.2.0
    • tools
    • None
    • 1.1.5
    • generic, x86, sparc
    • generic, solaris_2.1, solaris_2.4, solaris_2.5, solaris_2.5.1, windows_95, windows_nt
    • Verified

        See the attached sample program. If the inner classes make reference to a
        private method, you either get "cannot reference this until superclass
        constructor has been called" or the compiler goes into an infinite loop;
        the behavior depends on whether one inner class is generated or two are.

        If you remove the "private" qualifier from that method, it compiles fine.

        ===========================================================================

        roger.lewis@Eng 1997-07-17

        Synopsis: Annonymous class accessing private method hangs compiler.

        Description:
        Looks like a JDK 1.1 anonymous adapter accessing
        a private method of an enclosing classes will
        hang the compiler.

        Here is the code, which compiles fine when the
        visibility of the accessed method, bAction,
        is changed from private to protected.

        ************************************************
        import java.awt.*;
        import java.awt.event.*;

        public class PrivateTest {

           Frame f;

           private void bAction() {
              System.out.println("Thanks for the press!");
           }

           public PrivateTest() {
              f = new Frame();
              Button b = new Button("Press Me");

              b.addActionListener( new ActionListener () {
                 public void actionPerformed(ActionEvent e) {
                    bAction();
                 }
              } );
              
              f.add(b);
              f.pack();
              f.show();
           }

           public static void main(String args[]) {
              new PrivateTest();
           }
        }
        ************************************************

        Here's where it hangs:

        112 S% javac -verbose PrivateTest.java
        [parsed PrivateTest.java in 672 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/lang/Object.class) in 47 ms]
        [checking class PrivateTest]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Frame.class) in 63 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/lang/System.class) in 47 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/io/PrintStream.class) in 32 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/lang/String.class) in 62 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/io/Serializable.class) in 16 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/io/FilterOutputStream.class) in 0 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/io/OutputStream.class) in 0 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Window.class) in 62 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Container.class) in 94 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Component.class) in 172 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Component$NativeInLightFixer.class)
         in 16 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/Button.class) in 31 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/event/ActionListener.class) in 16 m
        s]
        [checking class PrivateTest. 1]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/util/EventListener.class) in 0 ms]
        [loaded E:\JDK1.1.3\lib\classes.zip(java/awt/event/ActionEvent.class) in 16 ms]
        ================================================================================


        daniel.indrigo@Canada 1997-08-26 Still doesn't work on Solaris with 1.1.3 1.1.4 or 1.2_ea2

        here's the example
        The compiler never stops when compiling the Java source code included below
        (tried for at least 10 minutes on a Sun Ultra-1). If the line containing "int
        i;" is left out, the compiler does not loop but exits with message:

        CompilerLoop.java:30: Can't reference this before the superclass constructor has been called.
        method2();
        ^
        Java source code:

        class A
        {
            void method1()
            {
        class Inner
        {
        void innerMethod()
        {
        method2();
        }
        };
        int i;
            }

            private void method2()
            {
            }
        }

        company - Technical University of Delft, The Netherlands , email - ###@###.###
        ==============================================================================

        john.bui@eng 1997-10-17

        No specific test case available. Implicity tested, closed with exposure.

              wmaddoxsunw William Maddox (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: