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

compiler is not recognising a constructor's signature in a packaged class

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.4

      Description

      Create a directory called "dumb". Put the following file in there:

      ---- dumb/Pair.java ----
      package dumb;
       
      public
      class Pair
      {
         protected Object k;
         protected Object v;
       
         Pair(Object kk, Object vv)
         {
            k = kk;
            v = vv;
         }
      }
      ---- end ----

      Put the following file in the current directory:

      ---- simple.java ----
      import dumb.Pair;
       
      class simple
      {
         simple()
         {
            Pair p = new Pair((Object) new String("a"), (Object) new String("b"));
         }
      }
      ---- end ----

      Now try to compile simple.java. When I do so, I get the following error from javac:

      ----
      $ javac simple.java
      simple.java:7: No constructor matching Pair(java.lang.Object, java.lang.Object) found in class dumb.Pair.
            Pair p = new Pair((Object) new String("a"), (Object) new String("b"));
                     ^
      1 error
      ----

      This does not make any sense, as far as I can tell. The compiler is failing to pick up the
      Pair(Object, Object) constructor in dumb/Pair.java; this even happens if I fully qualify
      every instance of Pair in simple.java (rewriting each as dumb.Pair).

      Note, however, that if I delete the package declaration from the beginning of
      dum/Pair.java, move that file into the current directory, get rid of the leading "dumb."
      from the import statement in simple.java, and recompile, javac works happily.

      I don't see anything in the October 31 draft of the Java language reference that might
      explain this behaviour, so I conclude for now that it is a serious bug in the compiler.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: