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

JDK 1.4 compiler throws NullPointerException after detecting duplicate class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.4.0
    • tools
    • x86
    • windows_2000


               GUINodeDisplayData child = (GUINodeDisplayData) children.nextElement();
               childCount += child.find( searchString, result );
            };

            return( count + childCount );
         }


      }
      ---------- END SOURCE ----------
      (Review ID: 143820)
      ======================================================================


      Name: nt126004 Date: 03/15/2002


      FULL PRODUCT VERSION :
      Using javac in JDK v1.4.0


      FULL OPERATING SYSTEM VERSION : Windows 2000 Professional


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Using ActivePerl v5.6.0 script to run compilation.


      A DESCRIPTION OF THE PROBLEM :
      Compiler threw exception after detecting a duplicate class.
      The problem as I see it:

      A new class was added to the package, but there was
      no "package ..." statement at the begining of the new class
      (I forgot). The new class made a reference to a class that
      was already there in the package. The compiler compiled
      the new class but did not put it into the same package as
      all the other classes. When the compiler compiled the
      class that was referenced in the new class, a duplicate
      class ID was detected. This was where the compiler
      detected the duplicate class, and then sometime after, the
      compiler threw the NullPointerException.


      Command line used in Perl script:
      c:/progra~1/jdk/bin/javac -deprecation -J-Xmx384m -source 1.4
      -classpath .;c:/progra~1/sharednet/src/classes;c:/progra~1/sh
      arednet/src/classes/xalan.jar;c:/progra~1/sharednet/src/clas
      ses/crimson.jar -d . *.java > Build.log 2>&1


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the two source classes given (in their own
      respective .java files) together on the command line with
      *.java.

      NOTE: I tried a simple test using simple classes, but the
      problem does not show up then. Only with the classes I've
      submitted.

      Ex: Compiling the following two classes detects the
      duplicate error but does not throw the
      NullPointerException. There may be attributes involved
      that are affecting the compiler.

      // First class
      class A
      {
         B ref;
         public A() {}
      }

      // Second class
      package mypackage;
      class B
      {
         int b;
         public B() { b = 0; }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Result: see Error Messages block.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      .\GUINodeDisplayData.java:20: duplicate class:
      gov.nasa.jpl.sharednet.tools.store_browser.GUINodeDisplayData
      public class GUINodeDisplayData extends DefaultMutableTreeNode
             ^
      An exception has occurred in the compiler (1.4.0). Please file a bug at the
      Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after
      checking the Bug Parade for duplicates. Include your program and the following
      diagnostic in your report. Thank you.
      java.lang.NullPointerException
      at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:439)
      at com.sun.tools.javac.v8.tree.Tree$VarDef.visit(Tree.java:503)
      at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:259)
      at com.sun.tools.javac.v8.comp.Attr.attribStat(Attr.java:296)
      at com.sun.tools.javac.v8.comp.Attr.attribStats(Attr.java:314)
      at com.sun.tools.javac.v8.comp.Attr._case(Attr.java:462)
      at com.sun.tools.javac.v8.tree.Tree$Block.visit(Tree.java:539)
      at com.sun.tools.javac.v8.comp.Attr.attribTree(Attr.java:259)
      at com.sun.tools.javac.v8.comp.Attr.attribStat(Attr.java:296)
      at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1489)
      at com.sun.tools.javac.v8.comp.Attr.attribClass(Attr.java:1456)
      at com.sun.tools.javac.v8.JavaCompiler.compile(JavaCompiler.java:396)
      at com.sun.tools.javac.v8.Main.compile(Main.java:526)
      at com.sun.tools.javac.Main.compile(Main.java:32)
      at com.sun.tools.javac.Main.main(Main.java:23)

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      //********** FIRST CLASS ; DON'T put this class in the package.


      import javax.swing.JOptionPane;
      import javax.swing.JDialog;
      import javax.swing.JTextField;
      import java.beans.*; //Property change stuff
      import java.awt.*;
      import java.awt.event.*;

      /**
       * Source taken from Sun example of a CustomDialog and modified.
       */
      class TextInputDialog extends JDialog
      {
          private String typedText = null;
          private GUINodeDisplayData newDataProcessor;

          private JOptionPane optionPane;

          public String getUserInputText()
          {
              return typedText;
          }

          public TextInputDialog(
             String title,
             String message,
             Frame aFrame,
             GUINodeDisplayData actionProcessor )
          {
              super( aFrame, true );

              setTitle( title );
              newDataProcessor = actionProcessor;


              final JTextField textField = new JTextField( 32 );
              Object[] array = { message, textField };

              final String btnString1 = "Enter";
              final String btnString2 = "Cancel";
              Object[] options = { btnString1, btnString2 };

              optionPane = new JOptionPane(
                 array,
                 JOptionPane.QUESTION_MESSAGE,
                 JOptionPane.YES_NO_OPTION,
                 null,
                 options,
                 options[0] );

              setContentPane( optionPane );
              setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
              WindowAdapter listener = new WindowAdapter()
              {
                 public void windowClosing( WindowEvent we )
                 {
                    /*
                     * Instead of directly closing the window,
                     * we're going to change the JOptionPane's
                     * value property.
                     */
                     optionPane.setValue(
                        new Integer( JOptionPane.CLOSED_OPTION ) );
                  }
              };
              addWindowListener( listener );

              ActionListener enterButtonListener = new ActionListener()
              {
                  public void actionPerformed( ActionEvent e )
                  {
                      optionPane.setValue( btnString1 );
                  }
              };
              textField.addActionListener( enterButtonListener );

              PropertyChangeListener propertyChangeListener = new
      PropertyChangeListener()
              {
                  public void propertyChange( PropertyChangeEvent e )
                  {
                      String prop = e.getPropertyName();

                      if( isVisible() &&
                        ( e.getSource() == optionPane ) &&
                        ( prop.equals( JOptionPane.VALUE_PROPERTY ) ||
                          prop.equals( JOptionPane.INPUT_VALUE_PROPERTY ) ) )
                      {
                          Object value = optionPane.getValue();

                          if( value == JOptionPane.UNINITIALIZED_VALUE )
                          {
                              // ignore reset
                              return;
                          }

                          // Reset the JOptionPane's value.
                          // If you don't do this, then if the user
                          // presses the same button next time, no
                          // property change event will be fired.
                          optionPane.setValue( JOptionPane.UNINITIALIZED_VALUE );

                          if( value.equals( btnString1 ) )
                          {
                              typedText = textField.getText();
                              String ucText = typedText.toUpperCase();

                              newDataProcessor.processNewInput( typedText );
                          };

                          setVisible( false );
                          typedText = null;
                      };
                  }
              };
              optionPane.addPropertyChangeListener( propertyChangeListener );
          }
      }





      //************************ SECOND CLASS


      package gov.nasa.jpl.sharednet.tools.store_browser;


      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Toolkit;
      import javax.swing.tree.*;
      import java.util.Vector;
      import java.util.Enumeration;

      //================================================================
      /**
       * This class holds data to be displayed in a node of a JTree.
       * It contains color and font information so that the node data
       * can be rendered with customized color and font.
       * <p>
       * Source taken from examples and modified.
       * <p>
       * @author Charles Pham
       */
      //================================================================
      public class GUINodeDisplayData extends DefaultMutableTreeNode
      {
         protected static Font[] m_fontsTable;

         protected Font m_font = null;
         protected Color m_textColor = Color.black;
         protected String m_displayData = "-void-";

         static
         {
            String[] fontNames;
            String[] names;

            try
            {
               fontNames = Toolkit.getDefaultToolkit().getFontList();
            }
            catch( Exception e )
            {
               fontNames = null;
            };

            if( fontNames == null || fontNames.length == 0 )
            {
               names = new String[]
               {
                  "Unknown font 1", "Unknown font 2"
               };
            }
            else
            {
               // Create the Fonts, creating fonts is slow, much better to
               // do it once.
               int fontSize = 16;

               names = fontNames;
               m_fontsTable = new Font[names.length];
               for( int counter = 0, maxCounter = names.length;
                    counter < maxCounter; counter++)
               {
                  try
                  {
                     m_fontsTable[counter] = new Font( fontNames[counter], 0,
      fontSize );
                  }
                  catch( Exception e )
                  {
                     m_fontsTable[counter] = null;
                  };

                  fontSize = ((fontSize + 2 - 12) % 12) + 12;
               };

            };

         }

         //----------------------------------------------------------------
         /**
          * Constructor
          * <p>
          * @param newString the new text to be displayed.
          */
         //----------------------------------------------------------------
         public GUINodeDisplayData( String newString )
         {
            m_font = m_fontsTable[0];
            m_displayData = newString;
         }

         //----------------------------------------------------------------
         /**
          * Constructs a new instance of SampleData with the passed in
          * arguments.
          * <p>
          * @param newString the new text to be displayed.
          * @param newColor the color to be used when rendering the text.
          * @param newFont the font to be used when rendering the text.
          */
         //----------------------------------------------------------------
         public GUINodeDisplayData(
            String newString,
            Color newColor,
            Font newFont )
         {
            m_displayData = newString;
            m_textColor = newColor;
            m_font = newFont;

            if( newFont == null )
            {
               m_font = m_fontsTable[0];
            };
         }

         //----------------------------------------------------------------
         /**
          * This method allows for adding of a new child node to the
          * current node.
          * <p>
          * @param nodeData the new text to be displayed.
          */
         //----------------------------------------------------------------
         public void addChildNode( String nodeData )
         {
            GUINodeDisplayData child = new GUINodeDisplayData( nodeData );
            add( child );
         }

         //----------------------------------------------------------------
         /**
          * This method allows for adding of a new child node to the
          * current node.
          * <p>
          * @param nodeData the new text to be displayed.
          * @param textColor the color to be used when rendering the text.
          */
         //----------------------------------------------------------------
         public void addChildNode( String nodeData, Color textColor )
         {
            GUINodeDisplayData child = new GUINodeDisplayData(
               nodeData,
               textColor,
               null );
            add( child );
         }

         //----------------------------------------------------------------
         /**
          * This method allows for adding of a new child node to the
          * current node.
          * <p>
          * @param nodeData the new text to be displayed.
          * @param textColor the color to be used when rendering the text.
          * @param font the font to be used when rendering the text.
          */
         //----------------------------------------------------------------
         public void addChildNode(
            String nodeData,
            Color textColor,
            Font font )
         {
            GUINodeDisplayData child = new GUINodeDisplayData(
               nodeData,
               textColor,
               font );
            add( child );
         }

         //----------------------------------------------------------------
         /**
          * Sets the font that is used to represent this object.
          * <p>
          * @param newFont the font to be used when rendering the text
          * data.
          */
         //----------------------------------------------------------------
         public void setFont( Font newFont )
         {
            if( m_font != null )
            {
               m_font = newFont;
            };
         }

         //----------------------------------------------------------------
         /**
          * Returns the Font used to represent this object.
          */
         //----------------------------------------------------------------
         public Font getFont()
         {
            return m_font;
         }

         //----------------------------------------------------------------
         /**
          * Sets the color used to draw the text.
          * <p>
          * @param newTextColor the new color to be used when rendering
          * the text data.
          */
         //----------------------------------------------------------------
         public void setTextColor( Color newTextColor )
         {
            m_textColor = newTextColor;
         }

         //----------------------------------------------------------------
         /**
          * Returns the color used to draw the text.
          */
         //----------------------------------------------------------------
         public Color getTextColor()
         {
            return m_textColor;
         }

         //----------------------------------------------------------------
         /**
          * Sets the string to display for this object.
          * <p>
          * @param newDisplayData the string to be displayed for the node.
          */
         //----------------------------------------------------------------
         public void setDisplayData( String newDisplayData )
         {
            if( newDisplayData != null )
            {
               m_displayData = newDisplayData;
            };
         }

         //----------------------------------------------------------------
         /**
          * Returns the string to display for this object.
          */
         //----------------------------------------------------------------
         public String getDisplayData()
         {
            return m_displayData;
         }

         public String toString()
         {
            return m_displayData;
         }


         //----------------------------------------------------------------
         /**
          * Search all children nodes for a sub-string. If the node data
          * string contains the sub-string, then the path to that node
          * will be added to the result vector.
          * <p>
          * @param searchString the sub-string to find within the nodes.
          * @param result the vector container to hold the results.
          */
         //----------------------------------------------------------------
         public int find( String searchString, Vector result )
         {
            int count = 0;
            if( m_displayData.trim().indexOf( searchString ) >= 0 )
            {
               // This is a node that matches to what we're looking for;
               // save it in the result container.
               TreeNode[] objectPath = getPath();
               TreePath path = new TreePath( objectPath );
               result.add( (Object) path );
               count++;
            };

            // Search children nodes as well.
            int childCount = 0;
            Enumeration children = children();
            while( children.hasMoreElements() )
            {

            gafter Neal Gafter (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: