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

Compiling module-info with package with only package-info or resources fails

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Tested with Java 11 - 23, everywhere the same.

      A DESCRIPTION OF THE PROBLEM :
      When trying to compile a `module-info.java` file that exports a package which only contains a `package-info.java` file or a resource file, compilation fails complaining about empty or missing package. In the `package-info.java` case this might be acceptable as the file only holds information about the package but itself does not mean anything is inside the package. But if there are resources in the package (supplied via `--patch-module`) the package should not be considered empty.

      Currently you cannot (or I just didn't find a way) compile a `module-info.java` file without also having at least one Java source file that is either compiled along or supplied via `--patch-module`. This sometimes is necessary to build special "resources-only" JAR files which can then be consumed by a modular application.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Given these files:
      ```
      $ find -type f -exec sh -c 'echo; echo {}; cat {}' \;

      ./res/pkg/res.txt
      foo

      ./src/module-info.java
      module mod {
          exports pkg;
      }

      ./src/pkg/A.java
      package pkg;

      class A {
      }

      ./src/pkg/package-info.java
      package pkg;
      ```

      This commando fails as expected with "src\module-info.java:2: error: package is empty or does not exist: pkg"
      ```
      rm -rf bin* && javac -d bin src/module-info.java
      ```

      These three work as exepcted:
      ```
      rm -rf bin* && javac -d bin src/module-info.java src/pkg/A.java
      rm -rf bin* && javac -d bin2 src/pkg/A.java && javac -d bin src/module-info.java --patch-module mod=bin2
      rm -rf bin* && javac -d bin src/module-info.java --patch-module mod=src
      ```

      These two fail with "src\module-info.java:2: error: package is empty or does not exist: pkg".
      The first might be acceptable, but the second should work.
      ```
      rm -rf bin* && javac -d bin src/module-info.java src/pkg/package-info.java
      rm -rf bin* && javac -d bin src/module-info.java --patch-module mod=res
      ```


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      You can compile a `module-info.java` file for a resources-only module
      ACTUAL -
      src\module-info.java:2: error: package is empty or does not exist: pkg

      CUSTOMER SUBMITTED WORKAROUND :
      ```
      mkdir -p dummy/pkg
      echo "package pkg;" >dummy/pkg/Dummy.java
      rm -rf bin* && javac -d bin src/module-info.java --patch-module mod=dummy
      ```


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: