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: java.nio.ByteBuffer.clear #117

Closed
vladp opened this issue Jan 27, 2019 · 1 comment
Closed

java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear #117

vladp opened this issue Jan 27, 2019 · 1 comment
Labels
duplicate Same as another issue

Comments

@vladp
Copy link

vladp commented Jan 27, 2019

Hello
I started getting this run time error all of a sudden (I upgraded to 0.6.2), but kept java version unchanged.

Not sure at this point if the problem on my side or in lmdbjava.
I am storing images in the database, not text. The error seems to be coming when I am retreiving an image.

implementation group: 'org.lmdbjava', name: 'lmdbjava', version: '0.6.2'

java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)


java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
	at org.lmdbjava.ByteBufferProxy$UnsafeProxy.out(ByteBufferProxy.java:297)
	at org.lmdbjava.ByteBufferProxy$UnsafeProxy.out(ByteBufferProxy.java:260)
	at org.lmdbjava.KeyVal.valOut(KeyVal.java:133)
	at org.lmdbjava.Dbi.get(Dbi.java:239)

My code invoking Dbi.get is this

    public static ByteBuffer getContent_impl_lmdb(final String itemKey,
                                             org.lmdbjava.Env env,
                                             Dbi<ByteBuffer> db ) throws IOException
    {
        if (env==null) { return null;}
        final ByteBuffer key = allocateDirect(env.getMaxKeySize());
        key.put(itemKey.getBytes(StandardCharsets.UTF_8))
                .flip();

        try (Txn<ByteBuffer> txn = env.txnRead()) {
            final ByteBuffer found = db.get(txn, key);
            if (found!= null) {
                // The fetchedVal is read-only and points to LMDB memory
                final ByteBuffer fetchedVal = txn.val();
                final ByteBufferBackedInputStream bo= new ByteBufferBackedInputStream(fetchedVal);
                ByteBuffer holdData= allocate(fetchedVal.remaining());
                int bytesRead=bo.read(holdData.array(), 0, fetchedVal.remaining());

                return holdData;
            }
            else {
                return null;
            }
        }
        catch (Exception ex) {
            logger.error("getContent_impl_lmdb ERROR: "+ex.toString());
            throw ex;
        }
        catch (OutOfMemoryError e) {
            final int MEGABYTE = (1024*1024);
            MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
            MemoryUsage heapUsage = memoryBean.getHeapMemoryUsage();
            long maxMemory = heapUsage.getMax() / MEGABYTE;
            long usedMemory = heapUsage.getUsed() / MEGABYTE;
            logger.error( "getContent_impl_lmdb:: Out of Memory Error : Memory Use :" + usedMemory + "M/" + maxMemory + "M");
            throw e;
        }
    } /*end of getContent_impl_lmdb */

I have not tried to re created consistenly. I am using lmdb for caching.
So I just removed my lmdb database to force my application force random caching again.
and at this point, I have not encountered the run time error again, but I only stressed the system
very slightly.

@benalexau benalexau added the duplicate Same as another issue label Jan 27, 2019
@benalexau
Copy link
Member

Duplicate of #116

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

No branches or pull requests

2 participants