Rectifies the java.lang.NoSuchMethodError when usinf printf (#172)
authorManish Kumar Thakur <manish3499@gmail.com>
Tue, 29 Jan 2019 13:44:19 +0000 (19:14 +0530)
committercyrille-artho <cyrille-artho@users.noreply.github.com>
Tue, 29 Jan 2019 13:44:19 +0000 (14:44 +0100)
* Rectifies the java.lang.NoSuchMethodError: java.util.regex.Matcher.find(I)Z error by overloading the find() method in native peer classes

* adds unit test

src/classes/java/util/regex/Matcher.java
src/peers/gov/nasa/jpf/vm/JPF_java_util_regex_Matcher.java
src/tests/gov/nasa/jpf/test/java/io/PrintStreamTest.java

index 8b1aac4805ede3d082bd1efd91abba62c25918e6..515318e94766b76ab55bd13256227f301c3d1a95 100644 (file)
@@ -67,6 +67,8 @@ public class Matcher {
   public native boolean matches();
   
   public native boolean find();
+
+  public native boolean find(int start);
   
   public native boolean lookingAt();
   
index b514846765810c39fbb6b6571019010096e4ac74..ebf9a215ceaed1f9621fb29cc219fa76f2466542 100644 (file)
@@ -73,6 +73,12 @@ public class JPF_java_util_regex_Matcher extends NativePeer {
     return matcher.matches();
   }
   
+  @MJI
+  public boolean find__I__Z (MJIEnv env, int objref, int i) {
+       Matcher matcher = getInstance( env, objref);
+    return matcher.find(i);
+  }
+
   @MJI
   public boolean find____Z (MJIEnv env, int objref) {
        Matcher matcher = getInstance( env, objref);
index 47556f27252692cae59de3464871f7c23559d6f0..6cadb3238ca1bbc07415d717452ab1e992ec8461 100644 (file)
@@ -30,13 +30,13 @@ import org.junit.Test;
  */
 public class PrintStreamTest extends TestJPF {
 
-  @Test // currently fails with: java.lang.NoSuchMethodError: java.util.regex.Matcher.find(I)Z
+  @Test 
   public void testPrintCharFormat () {
     if (verifyNoPropertyViolation()){
        ByteArrayOutputStream baos = new ByteArrayOutputStream(1);
        PrintStream baps = new PrintStream(baos, true);
-//     baps.printf("%c", 'a'); // fails
-//     assert (baos.toByteArray()[0] == 97);
+       baps.printf("%c", 'a'); 
+       assert (baos.toByteArray()[0] == 97);
     }
   }
-}
+}
\ No newline at end of file