-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
I got this exception
```
Caused by: java.lang.RuntimeException: Exception while creating a new instance for Pool
at java.xml@21.0.2/com.sun.org.apache.xml.internal.utils.ObjectPool.getInstance(ObjectPool.java:145)
at java.xml@21.0.2/com.sun.org.apache.xml.internal.utils.StringBufferPool.get(StringBufferPool.java:45)
at java.xml@21.0.2/com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.getStringValue(DOM2DTM.java:822)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.objects.XNodeSet.getStringFromNode(XNodeSet.java:219)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.objects.XNodeSet.str(XNodeSet.java:282)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.jaxp.XPathImplUtil.getResultAsType(XPathImplUtil.java:151)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:137)
... 10 more
```
Looking at the source code in the JDK gave me this:
```
try
{
return objectType.getConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException | SecurityException |
IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex){}
// Throw unchecked exception for error in pool configuration.
throw new RuntimeException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_EXCEPTION_CREATING_POOL, null));
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I compiled have this code block in my project
```
Document doc = fetchXmlMetadata(metadataUrl);
XPath xpath = XPathFactory.newInstance().newXPath();
String timestamp = (String) xpath.evaluate("//timestamp", doc, XPathConstants.STRING);
```
I compiled it with GraalVM to a native image and got the above stated exception in the line where `xpath.evaluate` is called.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to get the root cause of the error in the stacktrace.
So please fix the code in the JDK to
```
try
{
return objectType.getConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException | SecurityException |
IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex) {
// Throw unchecked exception for error in pool configuration.
throw new RuntimeException(ex, XMLMessages.createXMLMessage(
XMLErrorResources.ER_EXCEPTION_CREATING_POOL, null));
}
```
Thank you so much!
ACTUAL -
The root cause is lost and cannot be found in the stacktrace.
It is almost impossible to figure out, what really happened and how to fix the real problem.
CUSTOMER SUBMITTED WORKAROUND :
do not use xpath but write manual code to traverse the DOM.
FREQUENCY : always
I got this exception
```
Caused by: java.lang.RuntimeException: Exception while creating a new instance for Pool
at java.xml@21.0.2/com.sun.org.apache.xml.internal.utils.ObjectPool.getInstance(ObjectPool.java:145)
at java.xml@21.0.2/com.sun.org.apache.xml.internal.utils.StringBufferPool.get(StringBufferPool.java:45)
at java.xml@21.0.2/com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM.getStringValue(DOM2DTM.java:822)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.objects.XNodeSet.getStringFromNode(XNodeSet.java:219)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.objects.XNodeSet.str(XNodeSet.java:282)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.jaxp.XPathImplUtil.getResultAsType(XPathImplUtil.java:151)
at java.xml@21.0.2/com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:137)
... 10 more
```
Looking at the source code in the JDK gave me this:
```
try
{
return objectType.getConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException | SecurityException |
IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex){}
// Throw unchecked exception for error in pool configuration.
throw new RuntimeException(XMLMessages.createXMLMessage(
XMLErrorResources.ER_EXCEPTION_CREATING_POOL, null));
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I compiled have this code block in my project
```
Document doc = fetchXmlMetadata(metadataUrl);
XPath xpath = XPathFactory.newInstance().newXPath();
String timestamp = (String) xpath.evaluate("//timestamp", doc, XPathConstants.STRING);
```
I compiled it with GraalVM to a native image and got the above stated exception in the line where `xpath.evaluate` is called.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to get the root cause of the error in the stacktrace.
So please fix the code in the JDK to
```
try
{
return objectType.getConstructor().newInstance();
}
catch (InstantiationException | IllegalAccessException | SecurityException |
IllegalArgumentException | InvocationTargetException | NoSuchMethodException ex) {
// Throw unchecked exception for error in pool configuration.
throw new RuntimeException(ex, XMLMessages.createXMLMessage(
XMLErrorResources.ER_EXCEPTION_CREATING_POOL, null));
}
```
Thank you so much!
ACTUAL -
The root cause is lost and cannot be found in the stacktrace.
It is almost impossible to figure out, what really happened and how to fix the real problem.
CUSTOMER SUBMITTED WORKAROUND :
do not use xpath but write manual code to traverse the DOM.
FREQUENCY : always