question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NoSuchMethodError ByteBuffer.position running on Java 8 in 4.8.63

See original GitHub issue

I’m getting a weird error with latest 4.8.63:

Caused by: java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
	at nonapi.io.github.classgraph.fileslice.reader.RandomAccessFileReader.read(RandomAccessFileReader.java:93)
	at nonapi.io.github.classgraph.fileslice.reader.RandomAccessFileReader.readInt(RandomAccessFileReader.java:158)
	at nonapi.io.github.classgraph.fastzipfilereader.LogicalZipFile.readCentralDirectory(LogicalZipFile.java:450)
	at nonapi.io.github.classgraph.fastzipfilereader.LogicalZipFile.<init>(LogicalZipFile.java:155)
	at nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler$3.newInstance(NestedJarHandler.java:140)
	at nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler$3.newInstance(NestedJarHandler.java:135)
	at nonapi.io.github.classgraph.concurrency.SingletonMap.get(SingletonMap.java:189)
	at nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler$4.newInstance(NestedJarHandler.java:203)
	at nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler$4.newInstance(NestedJarHandler.java:150)
	at nonapi.io.github.classgraph.concurrency.SingletonMap.get(SingletonMap.java:189)
	at io.github.classgraph.ClasspathElementZip.open(ClasspathElementZip.java:140)

it looks like a binary incompatibility with your compile JDK and my runtime. I’m using 1.8.0-121. my version has

public abstract class Buffer {
    public final Buffer position(int newPosition) { ... }

// and

public abstract class ByteBuffer extends Buffer

In Java 9 they changed it to:

public abstract class Buffer {
    public Buffer position(int newPosition);

// and

public abstract class ByteBuffer extends Buffer {
    @Override
    public Buffer position(int newPosition) { ... }

I think you’ll need to do

-dstBuf.position(dstBufStart);
+((Buffer)dstBuf).position(dstBufStart);

in nonapi.io.github.classgraph.fileslice.reader.RandomAccessFileReader#read(long, java.nio.ByteBuffer, int, int) to make the library Java 8 compatible again.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
TWiStErRobcommented, Feb 17, 2020

That -booclasspath option is funny, if you have an older JDK lying around to get the rt.jar from, might as well just use it to compile 😃 I really agree with this comment.

I like learning new weird things in tech, thanks for the discussion 😃

0reactions
lukehutchcommented, Feb 17, 2020

Thanks also, I learned a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ByteBuffer and the Dreaded NoSuchMethodError
When run on Java 1.8, this virtual method call will be resolved to Buffer#position(int) at runtime, whereas on Java 9 and later, it'd...
Read more >
Status - Bugs - Eclipse
Installed with Eclipseinstaller, I get the follwoing error on startup eclipse.buildId=4.12.0.I20190605-1800 java.version=1.8.0_222 java.vendor=Oracle ...
Read more >
Ask Question - Stack Overflow
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer · 1. Why can't you use the same jdk of ...
Read more >
Avoid ByteBuffer incompatibility when compiling with JDK9+
NoSuchMethodError : java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer This is because the generated byte code includes the static return type of ...
Read more >
I get a java.lang.NoSuchMethodError when using a java.nio ...
The problem was triggered by compiling with "openjdk version 11.0.3". Although it was compiled with target Java8, and did run under a 'regular'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found