directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r920308 - /directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
Date Mon, 08 Mar 2010 13:01:15 GMT
Author: seelmann
Date: Mon Mar  8 13:01:15 2010
New Revision: 920308

URL: http://svn.apache.org/viewvc?rev=920308&view=rev
Log:
Fix for DIRSTUDIO-585 (Do not modify the current thread's ClassLoader; or reset it afterwards)

Modified:
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java?rev=920308&r1=920307&r2=920308&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/utils/Utils.java
Mon Mar  8 13:01:15 2010
@@ -185,24 +185,40 @@
 
     public static String serialize( Object o )
     {
-        Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        XMLEncoder encoder = new XMLEncoder( baos );
-        encoder.writeObject( o );
-        encoder.close();
-        String s = LdifUtils.utf8decode( baos.toByteArray() );
-        return s;
+        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            XMLEncoder encoder = new XMLEncoder( baos );
+            encoder.writeObject( o );
+            encoder.close();
+            String s = LdifUtils.utf8decode( baos.toByteArray() );
+            return s;
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader( ccl );
+        }
     }
 
 
     public static Object deserialize( String s )
     {
-        Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
-        ByteArrayInputStream bais = new ByteArrayInputStream( LdifUtils.utf8encode( s ) );
-        XMLDecoder decoder = new XMLDecoder( bais );
-        Object o = decoder.readObject();
-        decoder.close();
-        return o;
+        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+        try
+        {
+            Thread.currentThread().setContextClassLoader( Utils.class.getClassLoader() );
+            ByteArrayInputStream bais = new ByteArrayInputStream( LdifUtils.utf8encode( s
) );
+            XMLDecoder decoder = new XMLDecoder( bais );
+            Object o = decoder.readObject();
+            decoder.close();
+            return o;
+        }
+        finally
+        {
+            Thread.currentThread().setContextClassLoader( ccl );
+        }
     }
 
 



Mime
View raw message