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

javax.annotation.processing.Filer.getResource throws NoSuchFileException instead of FileNotFoundException

    Details

      Description

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      64-bit version of Windows

      A DESCRIPTION OF THE PROBLEM :
      Calling javax.annotation.processing.Filer.getResource for a resource that does not exist now throws a NoSuchFileException. Previously it threw a FileNotFoundException.

      This means following code, which was valid in Java 8, now no longer catches the appropriate exception, but reports an error:

            try {
              String service = ...;

              //check whether the file was already written before
              FileObject f = filer.getResource( StandardLocation.CLASS_OUTPUT, "", "META-INF/services/" + service );

              //process the previous content and merge it with the new annotation information
              //...
            } catch ( FileNotFoundException x ) {
              // doesn't exist, so there is nothing to merge. Just write the new information
            } catch ( IOException x ) {
              processingEnv.getMessager().printMessage( Kind.ERROR, "Failed to load existing service definition files: " + x );
            }

      REGRESSION. Last worked in version 8u131

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Create an annotation processor that uses the technique above
      - Compile a project using that annotation processor

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No errors are reported, the code just remains working as it was.
      ACTUAL -
      The annotation processor now reports an error instead of catching the correct error

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      compile_samples:
          [mkdir] Created dir: C:\Project\distrib\samples\build_files\classes
          [javac] Compiling 2740 source files to C:\Project\distrib\samples\build_files\classes
          [javac] error: Failed to load existing service definition files: java.nio.file.NoSuchFileException: C:\Project\distrib\samples\build_files\classes\META-INF\services\samples.common.Service

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Make the annotation processor also catch the NoSuchFileException.

      This is only feasible if you have control over the source code of the annotation processor.

        Attachments

          Activity

            People

            • Assignee:
              darcy Joe Darcy
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: