1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 import java.io.*;
18 
19 import org.objectweb.asm.*;
20 
21 public class SpacesInSimpleName {
main(String args[])22   public static void main(String args[]) throws Exception {
23     String methodName = "method_with_spaces_"
24         + "20 "
25         + "a0\u00a0"
26         + "1680\u1680"
27         + "2000\u2000"
28         + "2001\u2001"
29         + "2002\u2002"
30         + "2003\u2003"
31         + "2004\u2004"
32         + "2005\u2005"
33         + "2006\u2006"
34         + "2007\u2007"
35         + "2008\u2008"
36         + "2009\u2009"
37         + "200a\u200a"
38         + "202f\u202f"
39         + "205f\u205f"
40         + "3000\u3000";
41 
42     ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
43 
44     cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Main",
45       null, "java/lang/Object", null);
46 
47     MethodVisitor mvMain = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
48       "main", "([Ljava/lang/String;)V", null, null);
49     mvMain.visitCode();
50     mvMain.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out",
51       "Ljava/io/PrintStream;");
52     mvMain.visitLdcInsn("Hello, world!");
53     mvMain.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream",
54       "println", "(Ljava/lang/String;)V", false);
55     mvMain.visitMethodInsn(Opcodes.INVOKESTATIC, "Main", methodName, "()V", false);
56     mvMain.visitInsn(Opcodes.RETURN);
57     mvMain.visitMaxs(0, 0); // args are ignored with COMPUTE_MAXS
58     mvMain.visitEnd();
59     MethodVisitor mvSpaces = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
60       methodName, "()V", null, null);
61     mvSpaces.visitCode();
62     mvSpaces.visitInsn(Opcodes.RETURN);
63     mvSpaces.visitMaxs(0, 0); // args are ignored with COMPUTE_MAXS
64     mvSpaces.visitEnd();
65 
66     cw.visitEnd();
67 
68     byte[] b = cw.toByteArray();
69     OutputStream out = new FileOutputStream("Main.class");
70     out.write(b, 0, b.length);
71     out.close();
72   }
73 }
74