Index: regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java =================================================================== --- regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java (revision 475869) +++ regex/src/test/java/org/apache/harmony/tests/java/util/regex/PatternTest.java (working copy) @@ -18,6 +18,14 @@ package org.apache.harmony.tests.java.util.regex; import junit.framework.TestCase; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -697,7 +705,34 @@ mat.matches(); assertEquals(15, mat.end()); } + + public void testSerialization() throws Exception { + File file = new File("objects.tmp"); + try { + FileOutputStream fos = new FileOutputStream(file); + try { + ObjectOutputStream oos = new ObjectOutputStream(fos); + Pattern pat = Pattern.compile("a*bc"); + oos.writeObject(pat); + oos.close(); + } finally { + fos.close(); + } + FileInputStream fis = new FileInputStream(file); + try { + ObjectInputStream ois = new ObjectInputStream(fis); + Object o = ois.readObject(); + ois.close(); + assertTrue(o instanceof Pattern); + } finally { + fis.close(); + } + } finally { + file.delete(); + } + } + public void testSOLQuant() { Pattern pat = Pattern.compile("$*", Pattern.MULTILINE); Matcher mat = pat.matcher("\n\n"); Index: regex/src/main/java/java/util/regex/Pattern.java =================================================================== --- regex/src/main/java/java/util/regex/Pattern.java (revision 475758) +++ regex/src/main/java/java/util/regex/Pattern.java (working copy) @@ -87,7 +87,7 @@ /** * Current pattern to be compiled; */ - private Lexer lexemes = null; + private transient Lexer lexemes = null; /** * Pattern compile flags; @@ -278,6 +278,7 @@ throws PatternSyntaxException { this.lexemes = new Lexer(regex, flags); this.flags = flags; + this.pattern = regex; start = processExpression(-1, this.flags, null); if (!lexemes.isEmpty()) { @@ -1244,6 +1245,7 @@ globalGroupIndex = -1; compCount = -1; consCount = -1; + backRefs = new FSet [BACK_REF_NUMBER]; compileImpl(pattern, flags);