Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchMethodError when running on Java 8 #79

Closed
osobolev opened this issue Aug 8, 2024 · 4 comments · Fixed by #80
Closed

java.lang.NoSuchMethodError when running on Java 8 #79

osobolev opened this issue Aug 8, 2024 · 4 comments · Fixed by #80

Comments

@osobolev
Copy link

osobolev commented Aug 8, 2024

Error in version 1.3.0. Stacktrace:

java.lang.NoSuchMethodError: java.nio.CharBuffer.limit(I)Ljava/nio/CharBuffer;
	at org.owasp.encoder.Encode$Buffer.encode(Encode.java:1325)
	at org.owasp.encoder.Encode.encode(Encode.java:1237)
	at org.owasp.encoder.Encode.forXml(Encode.java:756)
	at org.owasp.encoder.Encode.forHtml(Encode.java:145)

Error line looks like
_input.limit(remaining).position(0);

where _input is CharBuffer. Method limit(int) differs in Java 8 and Java 9: in Java 8 it is final in the base class Buffer, and in Java 9 it is overriden in CharBuffer with covariant return type.

Seems that it is compiled against Java >= 9, so that limit(int) is linked to CharBuffer.limit(int) which is missing in Java 8.

@osobolev
Copy link
Author

The solution is simple: in the root pom.xml change

                    <execution>
                        <id>compile-java-8</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </execution>

to

                    <execution>
                        <id>compile-java-8</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <release>8</release>
                        </configuration>
                    </execution>

@jeremylong
Copy link
Member

Thank you for providing the suggested fix.

@tngwoerleij
Copy link

Thank you for fixing this 😃 Do you have any plans to release this soon? It unfortunately currently blocks us from updating to 1.3.

@jeremylong
Copy link
Member

I'll be releasing this shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants