JDK-4672865 : LineEvent.toString() throws unexpected NullPointerException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-04-23
  • Updated: 2003-08-02
  • Resolved: 2003-08-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description

Name: abR10010			Date: 04/23/2002




The specification for the constructor of the javax.sound.sampled.LineEvent
class doesn't forbid its parameters of reference type to be set to null value.

However the test (see below) shows the LineEvent.toString() method throws
a NullPointerException for the LineEvent instance created by the
constructor if the LineEvent.Type parameter is equal to null value.

Also the test shows the LineEvent constructor throws
an IllegalArgumentException if the Line parameter is equal to null value.

This Exception is looks reasonable for such case but the spec should say explicitly
about the IllegalArgumentException.

Please note also that the IllegalArgumentException is thrown by the
constructor of the java.util.EventObject class, not by the LineEvent
constructor itself.

Such behavior is shown by the test running with JDK 1.4.1-beta-b08.


Please, see test log:

% java -version
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b08)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b08, mixed mode)

% java test

==> Test for LineEvent class:

>> LineEvent constructor for Line = null: 
>   PASSED: expected IllegalArgumentException was thrown:
java.lang.IllegalArgumentException: null source
	at java.util.EventObject.<init>(EventObject.java:34)
	at javax.sound.sampled.LineEvent.<init>(LineEvent.java:61)
	at test.run(test.java:31)
	at test.main(test.java:13)

>> LineEvent constructor for LineEvent.Type = null: 
>  No any Exception was thrown!
>  testedLineEvent.getType():
>   PASSED: producedType = null
>  testedLineEvent.toString():
##  FAILED: unexpected Exception was thrown:
java.lang.NullPointerException
	at javax.sound.sampled.LineEvent.toString(LineEvent.java:116)
	at test.run(test.java:86)
	at test.main(test.java:13)

==> test FAILED!
 
 
The test source:
------------------------------- test.java --------------------------------
// File: %Z%%M% %I% %E% 
// Copyright %G% Sun Microsystems, Inc. All Rights Reserved

import javax.sound.sampled.*;

public class test {

    static final int STATUS_PASSED = 0;
    static final int STATUS_FAILED = 2;
    static final int STATUS_TEMP = 95;
    
    public static void main(String argv[]) {
        int testExitStatus = run(argv, System.out) + STATUS_TEMP;
        System.exit(testExitStatus);
    }

    public static int run(String argv[], java.io.PrintStream out) {
        int testResult = STATUS_PASSED;
    
        out.println("\n==> Test for LineEvent class:");
    
        Line testLine = new TestLine();
        Line nullLine = null;

        LineEvent.Type testLineEventType = LineEvent.Type.OPEN;
        LineEvent.Type nullLineEventType = null;

        LineEvent testedLineEvent = null;
        out.println("\n>> LineEvent constructor for Line = null: ");
        try {
            testedLineEvent =
                new LineEvent(nullLine,  // the source Line of this event
                                testLineEventType, // LineEvent.Type - the event type
                                (long) 1000 // position - the number processed of sample frames
                                );
            out.println(">  No any Exception was thrown!");
            out.println(">  testedLineEvent.getType():");
            try {
                Line producedLine = testedLineEvent.getLine();
                out.println(">   PASSED: producedLine = " + producedLine);
            } catch (Throwable thrown) {
                out.println("##  FAILED: unexpected Exception was thrown:");
                thrown.printStackTrace(out);
                testResult = STATUS_FAILED;
            }
            out.println(">  testedLineEvent.toString():");
            try {
                String producedString = testedLineEvent.toString();
                out.println(">   PASSED: producedString = " + producedString);
            } catch (Throwable thrown) {
                out.println("##  FAILED: unexpected Exception was thrown:");
                thrown.printStackTrace(out);
                testResult = STATUS_FAILED;
            }
        } catch (IllegalArgumentException illegArgExcept) {
            out.println(">   PASSED: expected IllegalArgumentException was thrown:");
            illegArgExcept.printStackTrace(out);
        } catch (NullPointerException nullPE) {
            out.println(">   PASSED: expected NullPointerException was thrown:");
            nullPE.printStackTrace(out);
        } catch (Throwable thrown) {
            out.println("##  FAILED: unexpected Exception was thrown:");
            thrown.printStackTrace(out);
            testResult = STATUS_FAILED;
        }

        out.println("\n>> LineEvent constructor for LineEvent.Type = null: ");
        try {
            testedLineEvent =
                new LineEvent(testLine,  // the source Line of this event
                                nullLineEventType, // LineEvent.Type - the event type
                                (long) 1000 // position - the number processed of sample frames
                                );
            out.println(">  No any Exception was thrown!");
            out.println(">  testedLineEvent.getType():");
            try {
                LineEvent.Type producedType = testedLineEvent.getType();
                out.println(">   PASSED: producedType = " + producedType);
            } catch (Throwable thrown) {
                out.println("##  FAILED: unexpected Exception was thrown:");
                thrown.printStackTrace(out);
                testResult = STATUS_FAILED;
            }
            out.println(">  testedLineEvent.toString():");
            try {
                String producedString = testedLineEvent.toString();
                out.println(">   PASSED: producedString = " + producedString);
            } catch (Throwable thrown) {
                out.println("##  FAILED: unexpected Exception was thrown:");
                thrown.printStackTrace(out);
                testResult = STATUS_FAILED;
            }
        } catch (IllegalArgumentException illegArgExcept) {
            out.println(">   PASSED: expected IllegalArgumentException was thrown:");
            illegArgExcept.printStackTrace(out);
        } catch (NullPointerException nullPE) {
            out.println(">   PASSED: expected NullPointerException was thrown:");
            nullPE.printStackTrace(out);
        } catch (Throwable thrown) {
            out.println("##  FAILED: unexpected Exception was thrown:");
            thrown.printStackTrace(out);
            testResult = STATUS_FAILED;
        }

        if ( testResult == STATUS_FAILED ) {
            out.println("\n==> test FAILED!");
        } else {
            out.println("\n==> test PASSED!");
        }
        return testResult;
    }
}    // end of test class 

class TestLine implements Line {

    public void addLineListener(LineListener listener) {
    }

    public void close() {
    }

    public Control getControl(Control.Type control) {
        return null;
    }

    public Control[] getControls() {
        return new Control[0];
    }

    public Line.Info getLineInfo() {
        return null;
    }

    public boolean isOpen() {
        return false;
    }

    public boolean isControlSupported(Control.Type control) {
        return false;
    }

    public void open() {
    }

    public void removeLineListener(LineListener listener) {
    }
}
-------------------------------------------------------------------------
 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b14
14-06-2004

EVALUATION ###@###.### 2002-04-23 Should be fixed. Contains code changes so commit to Mantis. ###@###.### 2002-11-01 Not much time for mantis left. Since LineEvent objects are usually only created by the Java Sound implementation itself, not high priority. Commit to Tiger.
01-11-2002