Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-652

ResourceLoader returns NULL on missing Resources

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.0.0
    • 1.4.0
    • Utilities
    • None
    • -all-

    Description

      When using pdfbox-1.0.0.jar:
      ---------------------------------------
      public static void main(String[] args)

      { String mystr = org.apache.pdfbox.Version.getVersion(); System.out.println(mystr); }

      Leads to:
      Exception in thread "main" java.lang.NullPointerException
      at org.apache.pdfbox.Version.getVersion(Version.java:52)
      at Test1.main(Test1.java:10)

      Problem:
      ------------
      pdfbox-1.0.0.jar is missing the "pdfbox.version"-Resource, which was still available in pdfbox-0.8.0-incubating.jar. So the "getVersion" returns, what the Resource-Loader returns: null.
      This leads to the exception descibed above.

      I am wondering, if this behaviour is ok. I think it is missleading and can be traced down to a problem in the org.apache.pdfsbox.util.ResourceLoader:

      Beginning in Line 74:
      ----------------------------
      if( is == null )
      {
      File f = new File( resourceName );
      if( f.exists() )

      { is = new FileInputStream( f ); }
      }

      IMHO there should be added an else-statment:
      ---------------------------------------------------------------
      if( is == null )
      {
      File f = new File( resourceName );
      if( f.exists() )
      { is = new FileInputStream( f ); }

      else

      { throw new IOException( "Error: could not find resource '" + resourceName + "' on classpath." ); }

      }

      Perhaps it is a good idea to add a Boolean-Flag (boolean failIfNotFound) like in the loadProperties-method, so that it is still possible to query for the existence of a special Resource.

      Attachments

        Activity

          People

            Unassigned Unassigned
            scholtz Erik Scholtz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: