-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for loading String's larger than 65535
Fixes: quarkusio/quarkus#32507
- Loading branch information
Showing
3 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.gizmo; | ||
|
||
import static io.quarkus.gizmo.BytecodeCreatorImpl.MAX_STRING_LENGTH; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class GiganticStringTest { | ||
|
||
@Test | ||
public void exactCutoffSize() throws Exception { | ||
doTest(MAX_STRING_LENGTH); | ||
} | ||
|
||
@Test | ||
public void cutoffSizePlus1() throws Exception { | ||
doTest(MAX_STRING_LENGTH + 1); | ||
} | ||
|
||
@Test | ||
public void cutoffSizePlusSeven() throws Exception { | ||
doTest(MAX_STRING_LENGTH + 7); | ||
} | ||
|
||
@Test | ||
public void tenTimesTheCutoffSize() throws Exception { | ||
doTest(MAX_STRING_LENGTH * 10); | ||
} | ||
|
||
@Test | ||
public void thirteenTimesTheCutoffSizePlus13() throws Exception { | ||
doTest((MAX_STRING_LENGTH * 10) + 13); | ||
} | ||
|
||
private void doTest(int size) | ||
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, | ||
NoSuchMethodException { | ||
TestClassLoader cl = new TestClassLoader(getClass().getClassLoader()); | ||
try (ClassCreator creator = ClassCreator.builder().classOutput(cl).className("com.MyTest").interfaces(Supplier.class).build()) { | ||
MethodCreator method = creator.getMethodCreator("get", Object.class); | ||
char[] chars = new char[size]; | ||
Arrays.fill(chars, 'a'); | ||
chars[0] = 'f'; | ||
chars[size - 1] = 'l'; | ||
|
||
String str = new String(chars); | ||
|
||
method.returnValue(method.load(str)); | ||
} | ||
Class<?> clazz = cl.loadClass("com.MyTest"); | ||
Supplier myInterface = (Supplier) clazz.getDeclaredConstructor().newInstance(); | ||
Object o = myInterface.get(); | ||
Assert.assertEquals(String.class, o.getClass()); | ||
String s = o.toString(); | ||
Assert.assertEquals(size, s.length()); | ||
Assert.assertEquals('f', s.charAt(0)); | ||
Assert.assertEquals('l', s.charAt(size - 1)); | ||
Assert.assertEquals('a', s.charAt(size / 2)); | ||
} | ||
} |