svn commit: r1902203 - in /xmlgraphics/fop/trunk/fop-core/src: main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java

[email protected] Thu, 23 Jun 2022 13:00:32 -0000
Newsgroups gmane.text.xml.fop.cvs
Message-ID <[email protected]>
Author: ssteiner
Date: Thu Jun 23 13:00:32 2022
New Revision: 1902203

URL: http://svn.apache.org/viewvc?rev=1902203&view=rev
Log:
FOP-2897: Skip OOM during font OS scanning

Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=1902203&r1=1902202&r2=1902203&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java Thu Jun 23 13:00:32 2022
@@ -206,10 +206,10 @@ public class FontInfoFinder {
                 if (ttcNames == null) {
                     return null;
                 }
-            } catch (Exception e) {
+            } catch (Throwable e) {
                 if (this.eventListener != null) {
                     this.eventListener.fontLoadingErrorAtAutoDetection(this,
-                            fontURI.toASCIIString(), e);
+                            fontURI.toASCIIString(), new RuntimeException(e));
                 }
                 return null;
             } finally {
@@ -231,13 +231,13 @@ public class FontInfoFinder {
                     if (this.eventListener != null) {
                         customFont.setEventListener(this.eventListener);
                     }
-                } catch (Exception e) {
+                } catch (Throwable e) {
                     if (fontCache != null) {
                         fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified);
                     }
                     if (this.eventListener != null) {
                         this.eventListener.fontLoadingErrorAtAutoDetection(this,
-                                embedUri.toASCIIString(), e);
+                                embedUri.toASCIIString(), new RuntimeException(e));
                     }
                     continue;
                 }
@@ -258,13 +258,13 @@ public class FontInfoFinder {
                 if (this.eventListener != null) {
                     customFont.setEventListener(this.eventListener);
                 }
-            } catch (Exception e) {
+            } catch (Throwable e) {
                 if (fontCache != null) {
                     fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified);
                 }
                 if (this.eventListener != null) {
                     this.eventListener.fontLoadingErrorAtAutoDetection(this,
-                            embedUri.toASCIIString(), e);
+                            embedUri.toASCIIString(), new RuntimeException(e));
                 }
                 return null;
             }

Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java?rev=1902203&r1=1902202&r2=1902203&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/fonts/FontInfoFinderTestCase.java Thu Jun 23 13:00:32 2022
@@ -21,12 +21,17 @@ package org.apache.fop.fonts;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.net.URI;
 
 import org.junit.Assert;
 import org.junit.Test;
 
 import org.apache.commons.io.IOUtils;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.autodetect.FontInfoFinder;
@@ -44,4 +49,19 @@ public class FontInfoFinderTestCase {
         ttc.delete();
         Assert.assertNull(embedFontInfos);
     }
+
+    @Test
+    public void testOOMError() {
+        InternalResourceResolver rr = ResourceResolverFactory.createInternalResourceResolver(new File(".").toURI(),
+            new ResourceResolver() {
+                public Resource getResource(URI uri) {
+                    throw new Error();
+                }
+                public OutputStream getOutputStream(URI uri) {
+                    return null;
+                }
+            });
+        EmbedFontInfo[] embedFontInfos = new FontInfoFinder().find(new File(".").toURI(), rr, null);
+        Assert.assertNull(embedFontInfos);
+    }
 }