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

(bf) Buffer.position and other methods should include detail in IAE

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • None
    • core-libs
    • b76
    • Verified

        A DESCRIPTION OF THE REQUEST :
        The message included in the IllegalArgumentException thrown from Java.nio's Buffer class is "null".

        JUSTIFICATION :
        A message in the exception thrown would make it easier to understand what went wrong when trying to set the position or the limit of the Buffer.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Simple message describing what went wrong.
        ACTUAL -
        "null" message.

        ---------- BEGIN SOURCE ----------
        Not in a test case format, but you'll get the idea...


        public static void main(String[] args) throws InterruptedException {

        System.out.println("Java version: " + System.getProperty("java.version"));

        System.out.println("==== Test #1 ====");
        try {
        ByteBuffer bb = ByteBuffer.allocateDirect(1024);
        bb.position(1025);
        } catch (IllegalArgumentException e) {
        System.out.println("Caught exception of type : " + e.getClass());
        System.out.println("With Message: " + e.getMessage());
        e.printStackTrace();
        }

        Thread.sleep(100);

        System.out.println("==== Test #2 ====");
        try {
        ByteBuffer bb = ByteBuffer.allocateDirect(1024);
        bb.limit(1025);
        } catch (IllegalArgumentException e) {
        System.out.println("Caught exception of type : " + e.getClass());
        System.out.println("With Message: " + e.getMessage());
        e.printStackTrace();
        }
        }


        Which outputs:

        Java version: 1.8.0_25
        ==== Test #1 ====
        Caught exception of type : class java.lang.IllegalArgumentException
        With Message: null
        java.lang.IllegalArgumentException
        at java.nio.Buffer.position(Buffer.java:244)
        at BufferEnhTest.main(BufferEnhTest.java:13)
        ==== Test #2 ====
        Caught exception of type : class java.lang.IllegalArgumentException
        With Message: null
        java.lang.IllegalArgumentException
        at java.nio.Buffer.limit(Buffer.java:275)
        at BufferEnhTest.main(BufferEnhTest.java:26)

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

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

                Created:
                Updated:
                Resolved: