NPE in java.util.regex.Pattern.compile()
----------------------------------------

         Key: HARMONY-101
         URL: http://issues.apache.org/jira/browse/HARMONY-101
     Project: Harmony
        Type: Bug
  Components: Classlib  
    Reporter: Svetlana Samoilenko


According to 1.4.2 and 1.5 specifications for 
java.util.regex.Pattern.matches(String regex,CharSequence input)                
              
An invocation of this convenience method of the form 
        Pattern.matches(regex, input);
behaves in exactly the same way as the expression 
        Pattern.compile(regex).matcher(input).matches()

Harmony throws unspecified NPE for Pattern.compile and returns false instead of 
true for Pattern.matches().

Code to reproduce: 
import java.util.regex.Pattern;
public class test2 {
    public static void main(String[] args) {             
        System.out.println("boolean is 
true="+Pattern.matches("[,&&\\p{Punct}]", ","));
        System.out.println("boolean is 
true="+Pattern.compile("[,&&\\p{Punct}]").matcher(",").matches());          
    }
}
 Steps to Reproduce: 
1. Build Harmony (check-out on 2006-01-30) j2se subset as described in 
README.txt. 
2. Compile test2.java using BEA 1.4 javac 
> javac -d . test2.java 
3. Run java using compatible VM (J9) 
> java -showversion test2

Output: 
C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
java version "1.4.2_04" 
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, 
Native Threads, GC strategy: parallel) 
boolean is true=true
boolean is true=true

C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as 
applicable. 
boolean is true=false
java.lang.NullPointerException
        at test2.main(test2.java:5)

Suggested junit test case:
------------------------ PatternTest.java 
------------------------------------------------- 
import junit.framework.*; 
import java.util.regex.Pattern;

public class PatternTest extends TestCase { 
    public static void main(String[] args) { 
        junit.textui.TestRunner.run(PatternTest.class); 
    } 
    public void test_compile () { 
        assertTrue(Pattern.matches("[,&&\\p{Punct}]", ","));
        assertTrue(Pattern.compile("[,&&\\p{Punct}]").matcher(",").matches());  
                   
     } 
}





-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to