From e77d11a8dea5399816e280f2875e5f76f9f655b1 Mon Sep 17 00:00:00 2001 From: Chapman Flack Date: Sat, 30 Mar 2024 21:19:06 -0400 Subject: [PATCH] Consistent (SAX/DOM) wrapping of XML parse errors The logic that chooses wrapping SQLException subclass and SQLstate for XML parse exceptions and I/O exceptions in XMLCopier.saxCopy is now duplicated in AdjustingDOMSource.get. Addresses issue #481. --- .../postgresql/pljava/jdbc/SQLXMLImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pljava/src/main/java/org/postgresql/pljava/jdbc/SQLXMLImpl.java b/pljava/src/main/java/org/postgresql/pljava/jdbc/SQLXMLImpl.java index e0cc49a35..87f6e60b4 100644 --- a/pljava/src/main/java/org/postgresql/pljava/jdbc/SQLXMLImpl.java +++ b/pljava/src/main/java/org/postgresql/pljava/jdbc/SQLXMLImpl.java @@ -3933,6 +3933,10 @@ static void saxCopy(SAXSource sxs, SAXResult sxr) throws SQLException SAX2PROPERTY.LEXICAL_HANDLER.propertyUri(), lh); xr.parse(sxs.getInputSource()); } + /* + * If changing these wrapping conventions, change them also in + * AdjustingDOMSource.get() + */ catch ( SAXException e ) { throw new SQLDataException(e.getMessage(), "22000", e); @@ -5555,10 +5559,21 @@ public DOMSource get() throws SQLException } Exception e = exceptions(); - if ( null != e ) - throw normalizedException(e); - return ds; + if ( null == e ) + return ds; + + /* + * If changing these wrapping conventions, change them also in + * XMLCopier.saxCopy() + */ + if ( e instanceof SAXException ) + throw new SQLDataException(e.getMessage(), "22000", e); + + if ( e instanceof IOException ) + throw new SQLException(e.getMessage(), "58030", e); + + throw normalizedException(e); } @Override