harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r549946 - in /harmony/enhanced/classlib/trunk/modules/regex/src: main/java/java/util/regex/ main/java/org/apache/harmony/regex/internal/nls/ test/java/org/apache/harmony/tests/java/util/regex/
Date Fri, 22 Jun 2007 20:14:57 GMT
Author: tellison
Date: Fri Jun 22 13:14:56 2007
New Revision: 549946

URL: http://svn.apache.org/viewvc?view=rev&rev=549946
Log:
Apply patch HARMONY-4248 ([classlib][regex] java.util.regex.Pattern.compile(regex, flags)
throws unexpected exceptions on certain pattern)

Modified:
    harmony/enhanced/classlib/trunk/modules/regex/src/main/java/java/util/regex/Pattern.java
    harmony/enhanced/classlib/trunk/modules/regex/src/main/java/org/apache/harmony/regex/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternErrorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/regex/src/main/java/java/util/regex/Pattern.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/regex/src/main/java/java/util/regex/Pattern.java?view=diff&rev=549946&r1=549945&r2=549946
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/regex/src/main/java/java/util/regex/Pattern.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/regex/src/main/java/java/util/regex/Pattern.java
Fri Jun 22 13:14:56 2007
@@ -83,6 +83,17 @@
     public static final int CANON_EQ = 1 << 7;
     
     static final int BACK_REF_NUMBER = 10;
+    
+    /**
+     * Bit mask that includes all defined match flags
+     */
+    static final int flagsBitMask = Pattern.UNIX_LINES | 
+                                    Pattern.CASE_INSENSITIVE | 
+                                    Pattern.COMMENTS | 
+                                    Pattern.MULTILINE |  
+                                    Pattern.DOTALL | 
+                                    Pattern.UNICODE_CASE | 
+                                    Pattern.CANON_EQ;
 
     /**
      * Current <code>pattern</code> to be compiled;
@@ -259,6 +270,13 @@
 	 */
     public static Pattern compile(String regex, int flags)
             throws PatternSyntaxException {
+    	
+    	if ((flags != 0) &&
+    	   	((flags | flagsBitMask) != flagsBitMask)) {
+    	        	
+    	    throw new IllegalArgumentException(Messages.getString("regex.1C"));
+    	}
+    	
         AbstractSet.counter = 1;
 
         return new Pattern().compileImpl(regex, flags);

Modified: harmony/enhanced/classlib/trunk/modules/regex/src/main/java/org/apache/harmony/regex/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/regex/src/main/java/org/apache/harmony/regex/internal/nls/messages.properties?view=diff&rev=549946&r1=549945&r2=549946
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/regex/src/main/java/org/apache/harmony/regex/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/regex/src/main/java/org/apache/harmony/regex/internal/nls/messages.properties
Fri Jun 22 13:14:56 2007
@@ -42,3 +42,4 @@
 regex.19=Invalid octal escape sequence
 regex.1A=Illegal inline construct
 regex.1B=Pattern cannot be null
+regex.1C=Invalid match flags value

Modified: harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternErrorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternErrorTest.java?view=diff&rev=549946&r1=549945&r2=549946
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternErrorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternErrorTest.java
Fri Jun 22 13:14:56 2007
@@ -53,25 +53,14 @@
 		Pattern.compile("foo", flags);
 
 		// add invalid flags - should get IllegalArgumentException
-		/*
-		 * TODO: Inconsistency between the reference JDK behaviour and spec - exception is
-		 * not thrown
-		 */
-		/*
-		 * Valid test is:
-		 * flags |= 0xFFFFFFFF;
-		 * try {
-		 *   Pattern.compile("foo",flags);
-		 * } catch (IllegalArgumentException e) {
-		 *   // This is the expected exception
-		 * } catch (Exception e) {
-		 *   fail();
-		 * }
-		 */
-
-        /* Workaround test is: */
+        // regression test for HARMONY-4248
 		flags |= 0xFFFFFFFF;
-        // No exception expected to match incorrect the reference behaviour
-		Pattern.compile("foo", flags);
+		try {
+		    Pattern.compile("foo",flags);
+		} catch (IllegalArgumentException e) {
+		    // This is the expected exception
+		} catch (Exception e) {
+		    fail();
+		}
 	}
 }



Mime
View raw message