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

(bf) NewDirectByteBuffer always has order ByteOrder.BIG_ENDIAN

    XMLWordPrintable

Details

    • b13
    • generic
    • generic

    Description



      Name: rmT116609 Date: 05/06/2004


      A DESCRIPTION OF THE REQUEST :
      NewDirectByteBuffer always has order ByteOrder.BIG_ENDIAN, even when the order is ByteOrder.LITTLE_ENDIAN.

      The following might be a fix for this problem, except that isDirect() is abstract, so JVMs are not required to implement the isDirect() method:

      ByteBuffer bb = nativeMethodReturningDirectByteBuffer();
      if (bb.isDirect()) {
        bb.order(ByteOrder.nativeOrder());
      }

      Also note that passing a memory address from Java to C++ works similarly... C++ assumes the data is LITTLE_ENDIAN unless the ByteBuffer that refers to the address is explicitly given order ByteOrder.nativeOrder().

      JUSTIFICATION :
      isDirect() isn't the best solution. Maybe an isNative() method would be better?

      But preferably the ByteBuffer returned by NewDirectByteBuffer would already be ByteOrder.nativeOrder() by default.

      Someone on comp.lang.java.programmer suggested htonl or kind. I have no idea what these are, but possibly the would be a good solution to the whole big-endian little-endian mess.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Any ByteBuffer returned by NewDirectByteBuffer should have order ByteOrder.nativeOrder().

      Obvious, no?
      ACTUAL -
      ByteBuffer returned by NewDirectByteBuffer has order ByteOrder.BIG_ENDIAN, which is false, mis-leading, incorrect, etc.

      ---------- BEGIN SOURCE ----------
      ByteBuffer bb = nativeMethodReturningDirectByteBuffer();
      System.out.println("bb.order() " + bb.order());

      Complete C++ and Java source code is available here:
      http://www.alpha-mu.com/alpha/files/



      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      ByteBuffer bb = nativeMethodReturningDirectByteBuffer();
      if (bb.isDirect()) {
        bb.order(ByteOrder.nativeOrder());
      }
      (Incident Review ID: 261264)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: