Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3, 3.0.0 PDFBox
    • Fix Version/s: 2.0.4, 3.0.0 PDFBox
    • Component/s: PDModel
    • Labels:

      Description

      I understand that PDFBox is not yet thread-safe, however, from reading this comment on a similar ticket, it seems like the fonts should be thread safe and is something that we want to fix. However, I am experiencing an intermittent NullPointerException when running multi-threaded unit tests that attempt to read several PDFs at once (see details here.

      Inside FontMapperImpl.java the getProvider and setProvider methods are synchronised:

          public synchronized void setProvider(FontProvider fontProvider)
          {
              this.fontProvider = fontProvider;
              fontInfoByName = createFontInfoByName(fontProvider.getFontInfo());
          }
      
          /**
           * Returns the font service provider. Defaults to using FileSystemFontProvider.
           */
          public synchronized FontProvider getProvider()
          {
              if (fontProvider == null)
              {
                  setProvider(DefaultFontProvider.INSTANCE);
              }
              return fontProvider;
          }
      

      However, the calling code from the findFont() method is not synchronised:

              // make sure the font provider is initialized
              if (fontProvider == null)
              {
                  getProvider();
              }
      
              // first try to match the PostScript name
              FontInfo info = getFont(format, postScriptName);
              if (info != null)
              {
                  return info.getFont();
              }
      

      As a result, if multiple threads attempt to access this at once, thread A may be in the setProvider method and have set fontProvider, but still processing the creation of fontInfoByName - so thread B could attempt to access before initialised.

        Attachments

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              robhinds rob hinds
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: