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

(ch) sun.nio.ch.Util::checkBufferPositionAligned gives misleading/incorrect error

    XMLWordPrintable

Details

    • b20
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 22.04
      Java 20 EA

      A DESCRIPTION OF THE PROBLEM :
      The error message thrown here, says "Current location of the bytebuffer ... is not a multiple of the block size"

      https://github.com/openjdk/jdk/blob/861cc671e2e4904d94f50710be99a511e2f9bb68/src/java.base/share/classes/sun/nio/ch/Util.java#L505-L514

      If you open a FileChannel in O_DIRECT mode and use ByteBuffers with it, an unaligned read gives a misleading error message:

      Exception in thread "main" java.io.IOException: Current location of the bytebuffer (0) is not a multiple of the block size (512)
      at java.base/sun.nio.ch.Util.checkBufferPositionAligned(Util.java:513)

      This isn't true (you can do two reads, both with the buffer at location = 0, and the first might work while the second can fail)

      It should more accurately say "Current location ... is not a multiple of the block size, or is not aligned"
      and include the output of "bb.alignmentOffset(pos, alignment)" IMO



      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: