Giter Site home page Giter Site logo

Comments (15)

PeteSL avatar PeteSL commented on June 2, 2024 1

Linux x86_64 (Debian) graalvm JDK 21.0.2+13.1
The error, according to the JDK 8 source from OpenJDK, is occurring at line 1000 of the Parser:
// Check if this is an XSLTC extension element else if (uri.equals(TRANSLET_URI)) { node = new UnsupportedElement(uri, prefix, local, true); UnsupportedElement element = (UnsupportedElement)node; ErrorMsg msg = new ErrorMsg(ErrorMsg.UNSUPPORTED_EXT_ERR, getLineNumber(),local); element.setErrorMessage(msg); }
which is the line creating ErrorMsg which should call ErrorMsg(String, int, String). However, that does not match up with the OpenJDK source on GitHub which Parser.java line 1000 doesn't match with any ErrorMsg creation at all and the init area in ErrorMsg is for ErrorMsg(String code, SyntaxTreeNode node) which is not ErrorMsg(String, int, String) nor would the (String, int, String) version cause a NullPointerException. I will test a simplified XSLT with only the above templates and a template creating the basic tags needed to see if it still causes the exception. If it does, I will post it here in a comment.

from graal.

hamzaGhaissi avatar hamzaGhaissi commented on June 2, 2024

Hi can you please share a small reproducer of this issue with your OS and graalvm version ?

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

Here is a full XSLT that causes the error:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" xmlns:Date="xalan://java.util.Date" exclude-result-prefixes="xalan Date"> <xsl:output method="html"/> <xsl:template name="javaUTCDateTime"> <xsl:param name="longdate"/> <xsl:variable name="jDate" select="Date:new()"/> <xsl:value-of select="Date:setTime($jDate, number($longdate))"/> <xsl:value-of select="Date:toGMTString($jDate)"/> </xsl:template> <xsl:template name="javaYear"> <xsl:param name="longdate"/> <xsl:variable name="jDate" select="Date:new()"/> <xsl:value-of select="Date:setTime($jDate, number($longdate))"/> <xsl:value-of select="Date:getYear($jDate) + 1900"/> </xsl:template> <xsl:template name="DurationDisplay"> <xsl:param name="longdate"/> <xsl:variable name="seconds" select="(number($longdate) mod 60000) div 1000.0"/> <xsl:variable name="minutes" select="floor((number($longdate) div 60000) mod 60)"/> <xsl:variable name="hours" select="floor((number($longdate) div 3600000) mod 24)"/> <xsl:variable name="days" select="floor(number($longdate) div 86400000)"/> <xsl:value-of select="concat(format-number($days, '#0'), 'd', format-number($hours, '#0'), 'h', format-number($minutes, '#0'), 'm', $seconds, 's')"/> </xsl:template> <xsl:template match="/"> <html> <head> <title>Status Page</title> <meta content="noindex,nofollow" name="robots"/> </head> <body bgColor="#606060"> <center> </center> </body> </html> </xsl:template> </xsl:stylesheet>
I am bothered that the Parser line number does not match the OpenJDK line number but does match the ErrorMsg(String, SyntaxTreeNode) line number. The Parser line number does match the Java 8 code but then the ErrorMsg(String, int, String) is called, not the ErrorMsg(String, SyntaxTreeNode) constructor.

from graal.

hamzaGhaissi avatar hamzaGhaissi commented on June 2, 2024

Can also share the source code of the app you are running or reproducer ?

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

The reproducer line is:
xslt = transformerFactory.newTemplates(new StreamSource(Objects.requireNonNull(StatusListenerPort.class.getResourceAsStream("detail.xsl"), "Package detail.xml not found")));

but you can use any stream (Files.newInputStream, for instance) to feed the StreamSource with the xslt that I showed previously. Understand, this is not doing a transform, only creating the Template for transforming and it works with any JVM including the GraalVM JVM. It does not work within a native image.

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

More information:
The reason the failure is in newTemplates() is because I am calling that procedure twice (doesn't make sense it would throw an exception but...). If the newTemplates() is called once with an extension (tried with the xalan java extension and the EXSLT extension), the extensions are not included in the native-image binary. If you try loading another stylesheet with the extension, then you get the exception where it should not be anyway (should be giving an exception stating "unknown exception at line number"). It seems there may be a mismatch of what is included in the native-image vs. what is in a regular JVM (no extensions vs. xalan and EXSLT extensions) and the xalan compiled packages may have mismatched error reporting (never should be getting to getFileName() in ErrMsg.

from graal.

hamzaGhaissi avatar hamzaGhaissi commented on June 2, 2024

Is this the same stack trace your having

Exception in thread "main" javax.xml.transform.TransformerConfigurationException: java.net.MalformedURLException
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1077)
        at com.sample.HelloSampleApplication.main(HelloSampleApplication.java:23)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.net.MalformedURLException
        at [email protected]/java.net.URL.<init>(URL.java:806)
        at [email protected]/java.net.URL.<init>(URL.java:654)
        at [email protected]/java.net.URL.<init>(URL.java:590)
        at [email protected]/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:651)
        at [email protected]/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:150)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:861)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
        at [email protected]/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse(Parser.java:439)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse(Parser.java:524)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:478)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:575)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1036)
        ... 2 more
Caused by: java.lang.NullPointerException
        at [email protected]/java.net.URL.<init>(URL.java:712)
        ... 16 more
---------
java.net.MalformedURLException
        at [email protected]/java.net.URL.<init>(URL.java:806)
        at [email protected]/java.net.URL.<init>(URL.java:654)
        at [email protected]/java.net.URL.<init>(URL.java:590)
        at [email protected]/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:651)
        at [email protected]/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:150)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:861)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at [email protected]/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
        at [email protected]/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse(Parser.java:439)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse(Parser.java:524)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:478)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:575)
        at [email protected]/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1036)
        at com.sample.HelloSampleApplication.main(HelloSampleApplication.java:23)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.NullPointerException
        at [email protected]/java.net.URL.<init>(URL.java:712)
        ... 16 more

using the following

TransformerFactory transformerFactory = TransformerFactory.newInstance();
InputStream xsltStream = HelloSampleApplication.class.getClassLoader().getResourceAsStream("transform.xslt");
Source xslt = new StreamSource(xsltStream);

// Create a Transformer object from the XSLT source
Templates transformer = transformerFactory.newTemplates(xslt);

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

No, I posted the exception when I opened the issue. In -theory-, a single call to newTemplates() should not cause an exception as it is (reading the comments in the Xalan code) assumed that an unknown extension might be resolved at parsing time. However, what I was seeing is those unknown extensions (which are known in Java) causing an exception with the wrong call to ErrMsg (never should see getFileName() in the stack as an unknown extension causes a transformation exception that shows the parsed name of the extension and the line number in the XSLT. So it is a bug for newTempates() to cause an exception when it doesn't in Java.

from graal.

hamzaGhaissi avatar hamzaGhaissi commented on June 2, 2024

I was not able get the same exception as you, please create a reproducer, upload it to github, then share it with me

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

`import org.w3c.dom.;
import javax.xml.parsers.
;
import javax.xml.transform.;
import javax.xml.transform.dom.
;
import javax.xml.transform.stream.;
import java.nio.file.
;
import java.util.*;

public class sampl
{
private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();

public static void main(String[] args)
{
	try
	{
		Templates xslt = transformerFactory.newTemplates(new StreamSource(Objects.requireNonNull(Files.newInputStream(Paths.get("gensimpl.xsl")), "gensimpl.xsl not found")));
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}

}`
Use this with XSLT code I put previously in a file called gensimpl.xsl and it will run in Java and cause an exception with native-image.

from graal.

hamzaGhaissi avatar hamzaGhaissi commented on June 2, 2024

Thank you we are tracking this

from graal.

vjovanov avatar vjovanov commented on June 2, 2024

This looks like missing metadata. To make sure that the reflection for your image is configured correctly please add -H:ThrowMissingRegistrationErrors= to the native-image build arguments. If the resulting image fails in libraries that are not under your control, you can always use a package prefix to prevent that: -H:ThrowMissingRegistrationErrors=<package-prefix>.

If the application accidentally swallows the failure, one can add the following flag to the image build: -H:MissingRegistrationReportingMode=<Warn|Exit>. When set to -H:MissingRegistrationReportingMode=Warn the application will only print missing reflection, and with -H:MissingRegistrationReportingMode=Exit the application will exit immediately without throwing an exception.

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

As you suspected, this is an issue with what native-build is including with the javax.xml packages. It is -not- an issue with my code as I have already made sure to include all the resources my code directly uses.

I reran native-image with it set to warn instead of the default exit and got multiple errors (below). This is with my original application so there is use of the java.util.logging package as well. Also note the app does -not- use reflection but does use ServiceLoader (as does much of the Java base code below). The application services are not flagged so everything flagged is internal Java packages/classes, not application packages/classes

2024-03-21T03:33:41.123Z
STDOUT: com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path META-INF/services/javax.xml.parsers.DocumentBuilderFactory without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
[email protected]/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
[email protected]/javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:255)
[email protected]/java.security.AccessController.executePrivileged(AccessController.java:129)
[email protected]/java.security.AccessController.doPrivileged(AccessController.java:319)
2024-03-21T03:33:41.125Z
STDOUT: com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path META-INF/services/javax.xml.transform.TransformerFactory without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
[email protected]/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
[email protected]/javax.xml.transform.FactoryFinder$1.run(FactoryFinder.java:241)
[email protected]/java.security.AccessController.executePrivileged(AccessController.java:129)
[email protected]/java.security.AccessController.doPrivileged(AccessController.java:319)
2024-03-21T03:33:41.132Z
STDOUT: com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path sun/util/logging/resources/logging_en.properties without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
[email protected]/java.util.ResourceBundle$1.getBundle(ResourceBundle.java:410)
[email protected]/java.util.logging.Level.computeLocalizedLevelName(Level.java:295)
[email protected]/java.util.logging.Level.getLocalizedLevelName(Level.java:355)
[email protected]/java.util.logging.Level.getLocalizedName(Level.java:281)
2024-03-21T03:33:41.132Z
STDOUT: com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path sun/util/logging/resources/logging_en_US.properties without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
[email protected]/java.util.ResourceBundle$1.getBundle(ResourceBundle.java:410)
[email protected]/java.util.logging.Level.computeLocalizedLevelName(Level.java:295)
[email protected]/java.util.logging.Level.getLocalizedLevelName(Level.java:355)
[email protected]/java.util.logging.Level.getLocalizedName(Level.java:281)
2024-03-21T03:33:41.181Z
STDOUT: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet without it being registered for runtime reflection. Add com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
[email protected]/java.lang.ClassLoader.loadClass(ClassLoader.java:121)
[email protected]/com.sun.org.apache.xalan.internal.utils.ObjectFactory.findProviderClass(ObjectFactory.java:187)
[email protected]/com.sun.org.apache.xalan.internal.utils.ObjectFactory.findProviderClass(ObjectFactory.java:151)
[email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.makeInstance(Parser.java:987)
2024-03-21T03:33:41.181Z
STDOUT: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet without it being registered for runtime reflection. Add com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
[email protected]/java.lang.Class.forName(DynamicHub.java:1312)
[email protected]/com.sun.org.apache.xalan.internal.utils.ObjectFactory.findProviderClass(ObjectFactory.java:193)
[email protected]/com.sun.org.apache.xalan.internal.utils.ObjectFactory.findProviderClass(ObjectFactory.java:151)
[email protected]/com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.makeInstance(Parser.java:987)
2024-03-21T03:33:41.182Z
STDOUT: org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access method java.lang.NullPointerException#getException() without it being registered for runtime reflection. Add java.lang.NullPointerException#getException() to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
[email protected]/java.lang.Class.getMethod(DynamicHub.java:1060)
[email protected]/javax.xml.transform.TransformerException.printStackTrace(TransformerException.java:342)
net.ae5pl.util.LoggingSupport$LoggingSimpleUTCFormatter.format(LoggingSupport.java:181)
[email protected]/java.util.logging.StreamHandler.publish0(StreamHandler.java:240)
2024-03-21T03:33:41.197Z
STDOUT: com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path META-INF/services/java.nio.file.spi.FileTypeDetector without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
[email protected]/java.nio.file.Files.probeContentType(Files.java:1732)

from graal.

vjovanov avatar vjovanov commented on June 2, 2024

Note that XML from the JDK will not work in most cases even with resources configured as it will try to generate bytecodes at build time. We are working on fixing that.

Until XML in the JDK is fixed the only way to make XML work is to use the interpreter for XML from xalan.

from graal.

PeteSL avatar PeteSL commented on June 2, 2024

I don't know if it is a concern or not because it appears logging and java.nio.file.Files.probeContentType() are working but they also flagged on accessing their services files which tells me there is an issue with native-image including JDK services files. I know this is a reported issue with applications and module loading but it is working with classpath loading in the application. I am using classpath, not module-path to build this image because of the ServiceLoader issue with module-path reported in [https://github.com//issues/7634]

from graal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.