75481

Why do I get the following exception 'first argument to the non-static Java function'?

Question:

I get this exception:

FATAL ERROR: 'The first argument to the non-static Java function *** is not a valid object reference.'

This happens when I try to transform an XML document using the xml-maven-plugin.

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xml-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <goals> <goal>transform</goal> </goals> </execution> </executions> <configuration> <transformationSets> <transformationSet> <dir>target/generated/wsdl</dir> <stylesheet>src/test/resources/transform/my-transformation.xsl</stylesheet> <includes> <include>**/*.xsd</include> </includes> <outputDir>target/generated/wsdl</outputDir> </transformationSet> </transformationSets> </configuration> </plugin>

Error message

[INFO] --- xml-maven-plugin:1.0:transform (transform--xsd) @ my-pom --- Warning: org.apache.xerces.parsers.SAXParser: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized. Warning: org.apache.xerces.parsers.SAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized. Warning: org.apache.xerces.parsers.SAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized. ERROR: 'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.' FATAL ERROR: 'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.'

XSL Transformation file's content

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://mysite/mycreate" xmlns:xalan="http://xml.apache.org/xslt" xmlns:mytag="http://andreas/ps-transformations" version="2.0"> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes" xalan:indent-amount="4"/> <xsl:variable name="myAnnotations" select="document('element-list.xml')"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="xs:element"> <xsl:param name="myValue" select="normalize-space(mytag:isTheRightElement(@class))"/> <xsl:choose> <xsl:when test="$myValue=''"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <xsl:element name="xs:annotation"> <xsl:element name="xs:documentation"> <xsl:value-of select="$elementValue"/> </xsl:element> </xsl:element> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:function name="myTag:isTheRightElement"> <xsl:param name="class"/> <xsl:for-each select="$myAnnotations/elementList/element"> <xsl:if test="lower-case(@class) = 'something'"> <xsl:value-of select="text()"/> </xsl:if> </xsl:for-each> </xsl:function> </xsl:stylesheet>

Answer1:

Handling of calls from XSLT to Java is not defined in any standard - it depends entirely on which XSLT processor you are using.

Note also, if you're using Saxon, version 8.7 is VERY old (about 2006). The current version is 9.6.

Answer2:

I get this error when trying to transform using an XSLT 2.0 'stylesheet', but I use an XSLT 1.0 parser.

In my case, this happens when I remove the maven dependency of saxon, which is an XSLT 2.0 parser. The XSLT parser that comes with Java 7 can handle only XSLT 1.0.

Maven solution is to keep the Saxon:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xml-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>transform</goal> </goals> </execution> </executions> <configuration> <transformerFactory>net.sf.saxon.TransformerFactoryImpl</transformerFactory> <transformationSets> <transformationSet> <dir>src/main/resources/xml</dir> <stylesheet>src/main/resources/xslt/my-transformation.xsl</stylesheet> <includes> <include>**/*.xml</include> </includes> <outputDir>target/generated/wsdl</outputDir> </transformationSet> </transformationSets> </configuration> <dependencies> <dependency> <groupId>net.sf.saxon</groupId> <artifactId>Saxon-HE</artifactId> <version>9.6.0-5</version> </dependency> </dependencies> </plugin>

Recommend

  • SAXParseException localized
  • TextView carriage return not working
  • Obtaining DOCTYPE details using SAX (JDK 7)
  • How to read comment text with SAX Java parser
  • How to generate xml from xsd schema?
  • Saxon Xpath namespace
  • Jenkins build fails after running Cucumber tests on Java heap space exception
  • Exclude jar from war Maven 3
  • LR(k) to LR(1) grammar conversion
  • XslTransform with xml-stylesheet
  • cross combine two RDDs using pyspark
  • Parsing “python foo.py -DVAR1=9 -DVAR2=Off” with argparse
  • Changing One Tag Name in an XML File Using XSLT
  • How can we extract the main verb from a sentence?
  • Grails 3 - How to publish to Artifactory
  • File extension of zlib zipped html page?
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • “mvn clean generate-source” could not resolve dependencies
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • Regex to match a string not followed by anything
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • C: Incompatible pointer type initializing
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Abort upload large uploads after reading headers
  • Jetty Server not starting: Unable to establish loopback connection
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • NHibernate Validation Localization with S#arp Architecture
  • How to rebase a series of branches?
  • Cannot connect to cassandra from Spark
  • How can I send an e-mail from a vbs script
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • What is Eclipse's Declaration View used for?
  • Accessing IRQ description array within a module and displaying action names
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Why joiner is not used after Sequence generator or Update statergy
  • how does django model after text[] in postgresql [duplicate]
  • Getting Messege Twice Using IMvxMessenger