IBM Support

IZ80097: JAVA.UTIL.SCANNER.HASNEXTLINE() BEHAVES DIFFERENTLY FROM SUNJDK

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Error Message: Given a test case as follows:
    import java.util.Scanner;
    public class ScannerTest {
     public static void main(String<OSB><CSB> args) {
      Scanner scanner = new Scanner(System.in);
      System.out.println("Entering loop ...");
      while(scanner.hasNextLine()) {
       String line = scanner.nextLine();
       System.out.println("Got line \"" + line + "\"");
      }
     }
    }
    Conduct the test on SUNJDK:
    $ java ScannerTest
    Entering loop ...
    one
    Got line "one"
    two
    Got line "two"
    three
    Got line "three"
    As soon as I type a line and hit enter, the Java program
    receives it and prints out the line. However, using IBM's Java 6
    (on multiple systems, described below) the behavior is
    different. After the first line is typed, the Java pogram does
    nothing.
    $ java ScannerTest
    Entering loop ...
    one
    
    Then when another line is entered, the first line is actually
    processed by Java.
    $ java ScannerTest
    one
    two
    Got line "one"
    
    And so on. The latest line typed is never processed immediately.
    $ java ScannerTest
    one
    two
    Got line "one"
    three
    Got line "two"
    
    When CTRL-D is pressed at this point, the last line is processed
    at last.
    $ java ScannerTest
    one
    two
    Got line "one"
    three
    Got line "two"
    Got line "three"
    .
    Stack Trace: N/A
    .
    

Local fix

Problem summary

  • The problem is caused when customer uses Scanner.hasNextLine()
    to check whether there is any new lines from input by customer,
    like System.in.
    When customer input the first line, it won't break from waiting
    in hasNextLine() method.
    

Problem conclusion

  • This defect will be fixed in:
    6.0.0 SR9
    .
    The java.util.Scanner.hasNextLine() method has been updated to
    prevent such a different behavior from SUNJDK.
    .
    To obtain the fix:
    Install build 20100720 or later
    

Temporary fix

Comments

APAR Information

  • APAR number

    IZ80097

  • Reported component name

    JAVA CLASS LIBS

  • Reported component ID

    620700130

  • Reported release

    600

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2010-07-15

  • Closed date

    2010-07-21

  • Last modified date

    2013-02-13

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    JAVA CLASS LIBS

  • Fixed component ID

    620700130

Applicable component levels

  • R600 PSN

       UP

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSCVQ3Y","label":"Java Class Libraries"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"6.0","Edition":"","Line of Business":{"code":"","label":""}}]

Document Information

Modified date:
13 February 2013