Skip to content

Commit

Permalink
Merge pull request #69 from sjlee/sjlee-lzocompressor-realloc
Browse files Browse the repository at this point in the history
Fix for issue #68. By setting accessible to true, this code works
  • Loading branch information
rangadi committed May 27, 2013
2 parents db2d3b6 + 579bf44 commit 6bd174e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/java/com/hadoop/compression/lzo/LzoCompressor.java
Expand Up @@ -19,6 +19,7 @@
package com.hadoop.compression.lzo;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -245,8 +246,12 @@ private ByteBuffer realloc(ByteBuffer buf, int newSize) {
// Manually free the old buffer using undocumented unsafe APIs.
// If this fails, we'll drop the reference and hope GC finds it
// eventually.
Object cleaner = buf.getClass().getMethod("cleaner").invoke(buf);
cleaner.getClass().getMethod("clean").invoke(cleaner);
Method cleanerMethod = buf.getClass().getMethod("cleaner");
cleanerMethod.setAccessible(true);
Object cleaner = cleanerMethod.invoke(buf);
Method cleanMethod = cleaner.getClass().getMethod("clean");
cleanMethod.setAccessible(true);
cleanMethod.invoke(cleaner);
} catch (Exception e) {
// Perhaps a non-sun-derived JVM - contributions welcome
LOG.warn("Couldn't realloc bytebuffer", e);
Expand Down

0 comments on commit 6bd174e

Please sign in to comment.