OPERATING SYSTEM(S):
All platforms.
FULL JDK VERSION(S):
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
DESCRIPTION:
The java.util.Scaner class behaves differently between Java5 and Java6.
This may or may not be related to the change described by 6269946.
Reproduction instructions:
1. Compile the attached testcase.
2. Run the testcase on a 5.0 JRE: "java ShowBug inputfile.txt"
3. Run the testcase on a 6 JRE: "java ShowBug inputfile.txt"
4. Note the differing output.
Example results:
Java 5:
c:\>java ShowBug inputfile.txt
Start found
Middle found
End found
dropped out, next is END
Java 6:
c:\>java ShowBug inputfile.txt
Start found
dropped out, next is MIDDLE
Testcase Source:
---------------------------------------------------------------
ShowBug.java
---------------------------------------------------------------
import java.util.regex.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class ShowBug {
public static void main(String[] args) {
if (args.length > 0)
readFile(args[0]);
else
readFile(null);
}
private static void readFile(String fileName) {
Scanner scanner=null;
if ( fileName == null) {
scanner = new Scanner(System.in);
} else {
try {
File file = new File(fileName);
scanner = new Scanner(file);
} catch (FileNotFoundException e) {
System.err.printf("Can't find %s file , quiting\n", fileName);
System.exit(1);
}
}
if (scanner. findWithinHorizon("START",0) == null) {
System.err.println("Can't find start");
System.exit(1);
}
System.out.printf("Start found\n");
while (scanner.findInLine("MIDDLE") != null) {
// while (scanner.findWithinHorizon("MIDDLE",0) != null) {
System.out.println("Middle found");
if (scanner.hasNext("END")) {
System.out.printf("End found\n");
break;
}
}
System.out.printf("dropped out, next is %s\n", scanner.next());
scanner.close();
}
}
---------------------------------------------------------------
---------------------------------------------------------------
inputfile.txt
---------------------------------------------------------------
START
MIDDLE
END
stuff after end
---------------------------------------------------------------
All platforms.
FULL JDK VERSION(S):
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
DESCRIPTION:
The java.util.Scaner class behaves differently between Java5 and Java6.
This may or may not be related to the change described by 6269946.
Reproduction instructions:
1. Compile the attached testcase.
2. Run the testcase on a 5.0 JRE: "java ShowBug inputfile.txt"
3. Run the testcase on a 6 JRE: "java ShowBug inputfile.txt"
4. Note the differing output.
Example results:
Java 5:
c:\>java ShowBug inputfile.txt
Start found
Middle found
End found
dropped out, next is END
Java 6:
c:\>java ShowBug inputfile.txt
Start found
dropped out, next is MIDDLE
Testcase Source:
---------------------------------------------------------------
ShowBug.java
---------------------------------------------------------------
import java.util.regex.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class ShowBug {
public static void main(String[] args) {
if (args.length > 0)
readFile(args[0]);
else
readFile(null);
}
private static void readFile(String fileName) {
Scanner scanner=null;
if ( fileName == null) {
scanner = new Scanner(System.in);
} else {
try {
File file = new File(fileName);
scanner = new Scanner(file);
} catch (FileNotFoundException e) {
System.err.printf("Can't find %s file , quiting\n", fileName);
System.exit(1);
}
}
if (scanner. findWithinHorizon("START",0) == null) {
System.err.println("Can't find start");
System.exit(1);
}
System.out.printf("Start found\n");
while (scanner.findInLine("MIDDLE") != null) {
// while (scanner.findWithinHorizon("MIDDLE",0) != null) {
System.out.println("Middle found");
if (scanner.hasNext("END")) {
System.out.printf("End found\n");
break;
}
}
System.out.printf("dropped out, next is %s\n", scanner.next());
scanner.close();
}
}
---------------------------------------------------------------
---------------------------------------------------------------
inputfile.txt
---------------------------------------------------------------
START
MIDDLE
END
stuff after end
---------------------------------------------------------------