United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6513038 JDK6: scanner.findInLine() does not work with embedded flag expression "(?s)"
JDK-6513038 : JDK6: scanner.findInLine() does not work with embedded flag expression "(?s)"

Details
Type:
Bug
Submit Date:
2007-01-14
Status:
Closed
Updated Date:
2010-07-29
Project Name:
JDK
Resolved Date:
2007-03-09
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.util
CPU:
x86
Priority:
P3
Resolution:
Not an Issue
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
The result of following is different in JDK1.5 and JDK6.

  Scanner scanner = new Scanner("\n");
  String result = scanner.findInLine("(?s).*");
  System.out.print(result);

It seems that JDK6 does not work with embedded flag expression "(?s)".
I'm trying on Windows XP.

  JDK1.5 (1.5.0_10-b03)
	result : \n
  JDK6 (j1.6.0-b105, 1.6.0_01-ea-b02)
	result: null

The following example using Pettern and "(?s)" returns the
expected result on both JDK1.5 and JDK6, so it seems that
the behavior of Scanner class is changing.

  Pattern pattern = Pattern.compile("(?s).*");
  Matcher matcher = pattern.matcher("\n");
  System.out.println(matcher.matches());

                                    

Comments
EVALUATION

The direct trigger of this "regression" is the fix for 6269946.
While indeed this is a regression from 5.0 behavior, the fix is
definitely correct.  Scanner.findInLine() only tries to match
the input "up to" the next line separator, \n is a line separator,
there is nothing (empty string) between the current position and
the position of "next line separator", so the fineInLIne() is
expected to return "found nothing" in this scenario. Try
Scanner.findWithinHorizon("(?s).*", 0) instead.
                                     
2007-03-09



Hardware and Software, Engineered to Work Together