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

DirectByteBufferPool calls DirectByteBuffer#clean twice #21622

Closed
johanandren opened this issue Oct 4, 2016 · 0 comments
Closed

DirectByteBufferPool calls DirectByteBuffer#clean twice #21622

johanandren opened this issue Oct 4, 2016 · 0 comments
Labels
3 - in progress Someone is working on this ticket t:io
Milestone

Comments

@johanandren
Copy link
Member

DirectByteBuffer#clean() was called twice. (via reflection)
https://github.com/openjdk-mirror/jdk7u-jdk/blob/jdk7u6-b08/src/share/classes/java/nio/Direct-X-Buffer.java.template#L103

Cleaner#clean method was fetched but not called.
https://github.com/openjdk-mirror/jdk7u-jdk/blob/jdk7u6-b08/src/share/classes/sun/misc/Cleaner.java#L138

invoke cleaner method to Clean throws IllegalArgumentException

repl-example

scala> val cleanerMethod = Class.forName("java.nio.DirectByteBuffer").getMethod("cleane
cleanerMethod: java.lang.reflect.Method = public sun.misc.Cleaner java.nio.DirectByteBu

scala> cleanerMethod.setAccessible(true)

scala> val cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean")
cleanMethod: java.lang.reflect.Method = public void sun.misc.Cleaner.clean()

scala> cleanMethod.setAccessible(true)

scala> val bb = java.nio.ByteBuffer.allocateDirect(1000)
bb: java.nio.ByteBuffer = java.nio.DirectByteBuffer[pos=0 lim=1000 cap=1000]

scala> bb.isDirect
res2: Boolean = true

scala> val cleaner = cleanerMethod.invoke(bb)
cleaner: Object = sun.misc.Cleaner@79a7bfbc

scala> cleanerMethod.invoke(cleaner)
java.lang.IllegalArgumentException: object is not an instance of declaring class
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
  at java.lang.reflect.Method.invoke(Method.java:498)
  ... 32 elided

scala> cleanMethod.invoke(cleaner)
res4: Object = null
@johanandren johanandren changed the title DirectByteBufferPool calls DirectByteBuffer#clean twice i DirectByteBufferPool calls DirectByteBuffer#clean twice Oct 4, 2016
@johanandren johanandren added 3 - in progress Someone is working on this ticket t:io labels Oct 4, 2016
@johanandren johanandren added this to the 2.4.12 milestone Oct 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - in progress Someone is working on this ticket t:io
Projects
None yet
Development

No branches or pull requests

1 participant