Skip to content

Commit 0946bec

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents e53540f + d4579e3 commit 0946bec

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ you have compiler redefine a class and code already compiled to use the class wi
3939

4040
## Using the CachedCompiler.
4141

42-
In this example, you can configure the compiler to write the files to a speicifc directory when you are in debug mode.
42+
In this example, you can configure the compiler to write the files to a specific directory when you are in debug mode.
4343

4444
private static final CachedCompiler JCC = CompilerUtils.DEBUGGING ?
4545
new CachedCompiler(new File(parent, "src/test/java"), new File(parent, "target/compiled")) :

compiler/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>net.openhft</groupId>
2222
<artifactId>java-parent-pom</artifactId>
23-
<version>1.1.12</version>
23+
<version>1.1.13</version>
2424
<relativePath />
2525
</parent>
2626

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package mytest;
2+
3+
public interface IntConsumer {
4+
void accept(int num);
5+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package mytest;
2+
3+
import net.openhft.compiler.CompilerUtils;
4+
import org.junit.Test;
5+
6+
import java.net.URL;
7+
import java.net.URLClassLoader;
8+
9+
import static org.junit.Assert.fail;
10+
11+
public class RuntimeCompileTest {
12+
static String code = "package mytest;\n" +
13+
"public class Test implements IntConsumer {\n" +
14+
" public void accept(int num) {\n" +
15+
" if ((byte) num != num)\n" +
16+
" throw new IllegalArgumentException();\n" +
17+
" }\n" +
18+
"}\n";
19+
20+
@Test
21+
public void outOfBounds() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
22+
ClassLoader cl = new URLClassLoader(new URL[0]);
23+
Class aClass = CompilerUtils.CACHED_COMPILER.
24+
loadFromJava(cl, "mytest.Test", code);
25+
IntConsumer consumer = (IntConsumer) aClass.newInstance();
26+
consumer.accept(1); // ok
27+
try {
28+
consumer.accept(128); // no ok
29+
fail();
30+
} catch (IllegalArgumentException expected) {
31+
}
32+
}
33+
}
34+

0 commit comments

Comments
 (0)