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

Missing import can cause unpredictable errors in other files.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • generic, x86
    • generic, windows_nt



      Name: wm38563 Date: 10/28/98


      Missing an import statement from a java file
      can cause other java files to have unpredictable
      errors raised on them.
      These errors are reported before the errors
      regarding the missing import and sometimes the
      error about the missing import doesn't get
      reported at all.

      This makes finding the problem almost impossible
      when dealing with a large project.

      Here is a small example to demonstrate this.

      Save this text to TProp.java:
      ========start=======
      import java.util.*;

      public class TProp extends Properties
      {
        public TProp(InputStream in) throws IOException
        {
          load(in);
        }
      }
      =======end========

      and this text to Test.java:
      ========start=======
      import java.io.*;

      public class Test
      {
        public Test(InputStream in)
        {
          TProp test=new TProp(in);
          try {
            throw new IOException();
          } catch(IOException e) {
          }
        }
      }
      ========end=========

      Then run "javac Test.java".
      This should come up with the following output:
      Test.java:7: Class InputStream not found in new.
          TProp test=new TProp(in);
                     ^
      Test.java:9: Class IOException not found.
            throw new IOException();
                      ^
      Test.java:10: Class IOException not found.
          } catch(IOException e) {
                  ^
      .\.\TProp.java:5: Class InputStream not found.
        public TProp(InputStream in) throws IOException
               ^
      .\.\TProp.java:5: Class IOException not found in throws.
        public TProp(InputStream in) throws IOException
                                            ^
      .\.\TProp.java:7: Class InputStream not found in TProp(InputStream).
          load(in);
              ^
      6 errors

      Notice how errors are reported in Test.java first
      even though there is no problem in this file.
      The actual error is in TProp.java.

      In the case that I found in my own project the
      actual error was never reported. Instead the
      equivalent to the errors in Test.java were raised
      without any reference to the actual errors.
      (Review ID: 37716)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: