Skip to content

NoSuchMethodError ByteBuffer.position running on Java 8 in 4.8.63 #403

@TWiStErRob

Description

@TWiStErRob

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions