From 0bad9338f9269fc9ddf4e2f01bc71dda6ca418b9 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Wed, 8 Apr 2026 16:23:10 -0500 Subject: [PATCH] fix: register Xerces XML resource bundles for native image (#293) (#296) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In GraalVM native image the Xerces XML parser throws MissingResourceException (an unchecked exception) when it tries to format an error message for malformed input but cannot locate its message bundles. This exception was not caught by the existing `catch (XMLStreamException ignored)` blocks in XmlParser, causing it to propagate and crash S3 requests that arrive with non-XML bodies (e.g. CDK PutObject calls during asset publishing). Two-layer fix: - Widen all five catch blocks in XmlParser from XMLStreamException to Exception so any parse failure — regardless of cause — results in an empty/default return value, matching the documented contract of each method. - Add resource-config.json registering the three Xerces XML message bundles (XMLMessages, XMLSerializerMessages, xpath regex message) so the bundles are available at native image runtime and the MissingResourceException is not thrown in the first place. --- .../github/hectorvent/floci/core/common/XmlParser.java | 10 +++++----- .../META-INF/native-image/resource-config.json | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/META-INF/native-image/resource-config.json diff --git a/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java b/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java index 5ed1fa2881..5e8cf69f88 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java @@ -91,7 +91,7 @@ public final class XmlParser { } } r.close(); - } catch (XMLStreamException ignored) {} + } catch (Exception ignored) {} return result; } @@ -160,7 +160,7 @@ public final class XmlParser { } } r.close(); - } catch (XMLStreamException ignored) {} + } catch (Exception ignored) {} return result; } @@ -206,7 +206,7 @@ public final class XmlParser { } } r.close(); - } catch (XMLStreamException ignored) {} + } catch (Exception ignored) {} return result; } @@ -256,7 +256,7 @@ public final class XmlParser { } } r.close(); - } catch (XMLStreamException ignored) {} + } catch (Exception ignored) {} return result; } @@ -312,7 +312,7 @@ public final class XmlParser { } } r.close(); - } catch (XMLStreamException ignored) {} + } catch (Exception ignored) {} return result; } } diff --git a/src/main/resources/META-INF/native-image/resource-config.json b/src/main/resources/META-INF/native-image/resource-config.json new file mode 100644 index 0000000000..ecde45ea96 --- /dev/null +++ b/src/main/resources/META-INF/native-image/resource-config.json @@ -0,0 +1,7 @@ +{ + "bundles": [ + {"name": "com.sun.org.apache.xerces.internal.impl.msg.XMLMessages"}, + {"name": "com.sun.org.apache.xerces.internal.impl.msg.XMLSerializerMessages"}, + {"name": "com.sun.org.apache.xerces.internal.impl.xpath.regex.message"} + ] +}