JDK-6513038 : JDK6: scanner.findInLine() does not work with embedded flag expression "(?s)"
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-01-14
  • Updated: 2010-07-29
  • Resolved: 2007-03-09
Related Reports
Relates :  
The result of following is different in JDK1.5 and JDK6.

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

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");

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.