You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2021/11/02 15:45:23 UTC
Problems with newer Java versions and introspection
All,
Velocity v1.7
openjdk version "16.0.2" 2021-07-20
OpenJDK Runtime Environment (build 16.0.2+7-67)
OpenJDK 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
(Yes, I realize Velocity 1.7 is old but we haven't had time to evaluate
500+ templates for compatibility with later versions.)
I'm getting an error evaluating a template in a Java 16 VM. This
template shows information about X.509 certificates.
This is the error:
Exception: org.apache.velocity.exception.VelocityException:
ASTMethod.execute() : exception invoking method
'getSubjectAlternativeNames' in class sun.security.x509.X509CertImpl
Stack Trace:
org.apache.velocity.exception.VelocityException: ASTMethod.execute() :
exception invoking method "getSubjectAlternativeNames" in class
sun.security.x509.X509CertImpl
org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:208)
at
org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
[...]
Caused by:
org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl
cannot access class sun.security.x509.X509CertImpl (in module java.base)
because module java.base does not export sun.security.x509 to unnamed
module @ff8c08
jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:385)
[...]
My velocity code is just doing this:
#if($cert.subjectAlternativeNames)
.. print information about the SANs...
#end
I looked at my Java code and I'm getting all objects through standard
interfaces; I'm not mucking-around in the sun.* namespaces or anything
like that. The sun.security.x509.X509CertImpl class implements
java.security.cert.X509Certificate which is a standard interface and the
method java.security.cert.X509Certificate.getSubjectAlternativeNames is
defined on that interface.
Is it possible that UberspectImpl is choosing the "class-defined method"
over the "interface-defined method" when calling it, which is causing
this problem?
Is there any way around this issue?
Thanks,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Problems with newer Java versions and introspection
Posted by Lukasz Lenart <lu...@apache.org>.
Hi Chris,
You were hit by the Java modules system ;-) Try to add the following
command line arguments (or define a Maven profile):
--illegal-access=permit --add-opens
java.base/sun.security.x509=ALL-UNNAMED -Dillegal-access=permit
or with Maven profile
<profile>
<id>jdk17</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--illegal-access=permit
--add-opens java.base/sun.security.x509=ALL-UNNAMED
-Dillegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
wt., 2 lis 2021 o 16:45 Christopher Schultz
<ch...@christopherschultz.net> napisał(a):
>
> All,
>
> Velocity v1.7
> openjdk version "16.0.2" 2021-07-20
> OpenJDK Runtime Environment (build 16.0.2+7-67)
> OpenJDK 64-Bit Server VM (build 16.0.2+7-67, mixed mode, sharing)
>
> (Yes, I realize Velocity 1.7 is old but we haven't had time to evaluate
> 500+ templates for compatibility with later versions.)
>
> I'm getting an error evaluating a template in a Java 16 VM. This
> template shows information about X.509 certificates.
>
> This is the error:
>
> Exception: org.apache.velocity.exception.VelocityException:
> ASTMethod.execute() : exception invoking method
> 'getSubjectAlternativeNames' in class sun.security.x509.X509CertImpl
> Stack Trace:
> org.apache.velocity.exception.VelocityException: ASTMethod.execute() :
> exception invoking method "getSubjectAlternativeNames" in class
> sun.security.x509.X509CertImpl
> org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:208)
> at
> org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
> [...]
> Caused by:
> org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl
> cannot access class sun.security.x509.X509CertImpl (in module java.base)
> because module java.base does not export sun.security.x509 to unnamed
> module @ff8c08
> jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:385)
> [...]
>
> My velocity code is just doing this:
>
> #if($cert.subjectAlternativeNames)
> .. print information about the SANs...
> #end
>
> I looked at my Java code and I'm getting all objects through standard
> interfaces; I'm not mucking-around in the sun.* namespaces or anything
> like that. The sun.security.x509.X509CertImpl class implements
> java.security.cert.X509Certificate which is a standard interface and the
> method java.security.cert.X509Certificate.getSubjectAlternativeNames is
> defined on that interface.
>
> Is it possible that UberspectImpl is choosing the "class-defined method"
> over the "interface-defined method" when calling it, which is causing
> this problem?
>
> Is there any way around this issue?
>
> Thanks,
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org