1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.bcel.generic;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertNotEquals;
23
24 import org.junit.jupiter.api.Test;
25
26
27
28
29
30
31 class ConstantPoolGenKeyCollisionTest {
32
33 @Test
34 void testFieldrefNamesContainingDelimiter() {
35 final ConstantPoolGen cpg = new ConstantPoolGen();
36 final int a = cpg.addFieldref("A", "b&c", "I");
37 final int b = cpg.addFieldref("A&b", "c", "I");
38 assertNotEquals(a, b, "distinct fieldrefs collided to constant pool index " + a);
39 }
40
41 @Test
42 void testInterfaceMethodrefNamesContainingDelimiter() {
43 final ConstantPoolGen cpg = new ConstantPoolGen();
44 final int a = cpg.addInterfaceMethodref("I", "m#n", "()V");
45 final int b = cpg.addInterfaceMethodref("I#m", "n", "()V");
46 assertNotEquals(a, b, "distinct interface methodrefs collided to constant pool index " + a);
47 }
48
49 @Test
50 void testMethodrefDedupStillWorks() {
51 final ConstantPoolGen cpg = new ConstantPoolGen();
52 final int a = cpg.addMethodref("Foo", "bar", "()V");
53 final int b = cpg.addMethodref("Foo", "bar", "()V");
54 assertEquals(a, b, "identical methodrefs must reuse the same constant pool entry");
55 }
56
57 @Test
58 void testMethodrefNamesContainingDelimiter() {
59 final ConstantPoolGen cpg = new ConstantPoolGen();
60 final int a = cpg.addMethodref("Foo", "bar:baz", "()V");
61 final int b = cpg.addMethodref("Foo:bar", "baz", "()V");
62 assertNotEquals(a, b, "distinct methodrefs collided to constant pool index " + a);
63 }
64 }