harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r936870 - /harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
Date Thu, 22 Apr 2010 14:30:51 GMT
Author: regisxu
Date: Thu Apr 22 14:30:51 2010
New Revision: 936870

URL: http://svn.apache.org/viewvc?rev=936870&view=rev
Log:
specific encoding when creating String from byte array.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java

Modified: harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java?rev=936870&r1=936869&r2=936870&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/instrument/src/main/java/org/apache/harmony/instrument/internal/InstrumentationImpl.java
Thu Apr 22 14:30:51 2010
@@ -22,6 +22,7 @@ import java.lang.instrument.ClassFileTra
 import java.lang.instrument.Instrumentation;
 import java.lang.instrument.UnmodifiableClassException;
 import java.lang.reflect.Method;
+import java.io.UnsupportedEncodingException;
 import java.security.ProtectionDomain;
 
 import org.apache.harmony.instrument.internal.nls.Messages;
@@ -185,7 +186,7 @@ public class InstrumentationImpl impleme
         byte[] source = classfileBuffer;
         byte[] result = null;
         byte[] trans = null;
-        String className = new String(classNameBytes);
+        String className = utf8BytesToString(classNameBytes);
         for (ClassFileTransformer t : transformers) {
             try {
                 trans = t.transform(loader, className, classBeingRedefined,
@@ -207,10 +208,10 @@ public class InstrumentationImpl impleme
     private void executePremain(byte[] className, byte[] options) {
         try {
             ClassLoader loader = ClassLoader.getSystemClassLoader();
-            Class c = loader.loadClass(new String(className));
+            Class c = loader.loadClass(utf8BytesToString(className));
             Method method = c.getMethod("premain", PREMAIN_SIGNATURE); //$NON-NLS-1$
             method.invoke(null, new Object[] {
-                    null == options ? null : new String(options), this });
+                    null == options ? null : utf8BytesToString(options), this });
         } catch (Exception e) {
             e.printStackTrace();
             System.err
@@ -218,4 +219,18 @@ public class InstrumentationImpl impleme
             System.exit(1);
         }
     }
+
+    private static String utf8BytesToString(byte[] bytes) {
+        if (bytes == null) {
+            return null;
+        }
+
+        try {
+            return new String(bytes, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            // should never happen
+            throw new RuntimeException(e);
+        }
+    }
+
 }



Mime
View raw message