[ 
https://issues.apache.org/jira/browse/FOP-2954?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17525766#comment-17525766
 ] 

Jörg Weske commented on FOP-2954:
---------------------------------

Unfortunately, I cannot provide further resources as the problem happened 
onsite at one of our customers and they manually deleted the cache file to 
resolve the issue. We have been unable to successfully manipulate font cache 
files to reproduce the error using a hex editor or by replacing / truncating 
said files.

Manual removal of a defective file is no option in a production environment, as 
our users do not have any direct access to the server running our application 
and would have to raise a (potentially costly) ticket with their respective 
service providers to have the cache file deleted.

Catching the error in our own code from outside FOP and trying to resolve the 
problem by actively deleting the FOP fontcache on a mere hunch does not seem 
like an ideal solution.

Currently, we are using the following workaround:
{code:java}
  public static void clearFontCache() {
    File fontCacheFile = null;
    try {
      fontCacheFile = FontCache.getDefaultCacheFile(false);
      FontCache.loadFrom(fontCacheFile);
    } catch (Throwable ex) {
      if (fontCacheFile != null) {
        log(Level.WARNING, "Deleting defective FOP FontCache file.");
        try {
          fontCacheFile.delete();
        } catch (SecurityException warn) {
          log(Level.WARNING, "Could not delete defective FOP FontCache file \"" 
+ fontCacheFile.getAbsolutePath()
              + "\". Please remove manually.");
        }
      }
    }
  }

try {
   // create FOP file...
} catch (Throwable e) {
  if (e instanceof ClassCastException || e instanceof NoClassDefFoundError) {
    clearFontCache();
  }
  throw new CreatePdfFileException(e);
} {code}
PDF creation will still fail if a defective cache file is first encountered, 
but should work when retrying.

> Uncaught java.lang.ClassCastException in FontCache.loadFrom()
> -------------------------------------------------------------
>
>                 Key: FOP-2954
>                 URL: https://issues.apache.org/jira/browse/FOP-2954
>             Project: FOP
>          Issue Type: Bug
>          Components: font/unqualified
>    Affects Versions: 2.4
>            Reporter: Jörg Weske
>            Priority: Major
>         Attachments: stacktrace.txt
>
>
> In certain cases, de-serialization of a defective fontcache file can fail 
> with a java.lang.ClassCastException (see attached partial stacktrace).
> The exception should be caught inside FontCache.loadFrom() and the defective 
> cache file discarded, as with the two other exceptions that are already being 
> handled appropriately (ClassNotFoundException and IOException).



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to