From 37e181d6dcb58b97503bf435408d418b9dd6216f Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Mon, 17 Jun 2002 00:38:23 +0000 Subject: [PATCH] Fix bug I introduced with the class loader. I hang me head in shame as I did not look at the output of the unit tests. --- .../puppycrawl/tools/checkstyle/Configuration.java | 12 +++++++++--- .../tools/checkstyle/ConfigSerializationTest.java | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java index b06dc87ad..5172a291e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java @@ -40,7 +40,9 @@ import org.apache.regexp.RE; import org.apache.regexp.RESyntaxException; /** - * Represents the configuration that checkstyle uses when checking. + * Represents the configuration that checkstyle uses when checking. The + * configuration is Serializable, however the ClassLoader configuration is + * lost. * @author Oliver Burn **/ public class Configuration @@ -103,8 +105,11 @@ public class Configuration /** line numbers to ignore in header **/ private TreeSet mHeaderIgnoreLineNo = new TreeSet(); - /** class loader to resolve classes with **/ - private ClassLoader mLoader = + /** + * class loader to resolve classes with. Needs to be transient as unable + * to persist. + **/ + private transient ClassLoader mLoader = Thread.currentThread().getContextClassLoader(); /** where to place right curlies **/ @@ -275,6 +280,7 @@ public class Configuration aStream.defaultReadObject(); // initialize the transient fields + mLoader = Thread.currentThread().getContextClassLoader(); mRegexps = new HashMap(); try { // Loop on the patterns creating the RE's diff --git a/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java b/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java index ff28d6410..9952e085d 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/ConfigSerializationTest.java @@ -41,7 +41,7 @@ public class ConfigSerializationTest /** * Test that the RE deserialization mechanism works for one example. */ - public void testRegexpDesrialization() + public void testRegexpDeserialization() throws Exception { Configuration configOrig = new Configuration(); @@ -49,6 +49,7 @@ public class ConfigSerializationTest Configuration configCopy = copyBySerialization(configOrig); assertNotNull(configCopy); + assertNotNull(configCopy.getClassLoader()); // test that the general deserialization mechanism for RE fields works RE typeRegexp = configCopy.getTypeRegexp();