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

Javac reports error for source having same name in different directories

    Details

    • Subcomponent:
    • Introduced In Build:
      b53
    • Introduced In Version:
      9
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      I think I found a javac bug which is reproduced on Java 9/10/11, but not on Java 8.

      I created a repository with a minimal, reproducible and verifiable example: https://github.com/orionll/javac-bug

      There are three Java files:
      org/example/Common.java (empty file)
      org/example/impl/Common.java
      org/example/impl/Util.java

      Util.java imports org.example.* and refers to a Common.X field. This is a totally legitimate code, but javac fails with an error saying that org/example/Common.java does not contain a class org.example.Common (it doesn't have to).

      REGRESSION : Last worked in version 8u202

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      mkdir bin
      javac -sourcepath src src/org/example/Common.java src/org/example/impl/Common.java src/org/example/impl/Util.java -d bin

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The files successfully compile
      ACTUAL -
      src\org\example\impl\Util.java:7: error: cannot access Common
              System.out.println(Common.X);
                                 ^
        bad source file: src\org\example\Common.java
          file does not contain class org.example.Common
          Please remove or make sure it appears in the correct subdirectory of the sourcepath.
      1 error

      ---------- BEGIN SOURCE ----------
      // src/org/example/Common.java
      package org.example;

      // src/org/example/impl/Common.java
      package org.example.impl;

      final class Common {
          static final int X = 42;
      }

      // src/org/example/impl/Util.java
      package org.example.impl;

      import org.example.*;

      public class Util {
          public static void f() {
              System.out.println(Common.X);
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              jlahoda Jan Lahoda
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: