Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324960

Unsafe.allocateMemory documentation incorrect regarding zero return value

XMLWordPrintable

    • b09
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The documentation for the method `allocateMemory` of the classes `sun.misc.Unsafe` and `jdk.internal.misc.Unsafe` says:
      > The resulting native pointer will never be zero

      However, this seems to be incorrect. Calling the method with 0 as argument returns 0 as result:
      ```
      unsafe.allocateMemory(0)
      ```

      Maybe this is just a documentation error? The implementation has a special check for `bytes == 0` in which case it returns 0.

      Note that `reallocateMemory` behaves the same way, but there it is properly documented.


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: