Skip to content

Commit cd6ebec

Browse files
author
Jaroslav Tulach
committed
Removing IOException from PolyglotEngine.eval and other end-user facing methods not related to reading from streams
1 parent fbb6bb3 commit cd6ebec

File tree

21 files changed

+116
-146
lines changed

21 files changed

+116
-146
lines changed

truffle/com.oracle.truffle.api.instrumentation.test/src/com/oracle/truffle/api/instrumentation/InstrumentationTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,8 @@ public void testLanguageInstrumentationAndExceptions() throws IOException {
155155
try {
156156
engine.eval(Source.newBuilder("ROOT(EXPRESSION)").name("unknown").mimeType("testLanguageInstrumentation").build());
157157
Assert.fail("expected exception");
158-
} catch (IOException e) {
159-
// we assert that MyLanguageException is not wrapped into
160-
// InstrumentationException.
161-
if (!(e.getCause() instanceof MyLanguageException)) {
162-
Assert.fail(String.format("expected MyLanguageException but was %s in %s", e.getCause(), e));
163-
}
158+
} catch (MyLanguageException e) {
159+
// we assert that MyLanguageException is not wrapped
164160
}
165161
Assert.assertEquals(1, TestLanguageInstrumentationLanguage.installInstrumentsCounter);
166162
Assert.assertEquals(1, TestLanguageInstrumentationLanguage.createContextCounter);
@@ -224,7 +220,7 @@ protected Void createContext(com.oracle.truffle.api.TruffleLanguage.Env env) {
224220
}
225221

226222
@Override
227-
protected CallTarget parse(final Source code, Node context, String... argumentNames) throws IOException {
223+
protected CallTarget parse(final Source code, Node context, String... argumentNames) {
228224
return Truffle.getRuntime().createCallTarget(new RootNode(TestLanguageInstrumentationLanguage.class, null, null) {
229225

230226
@Child private BaseNode base = InstrumentationTestLanguage.parse(code);
@@ -841,7 +837,7 @@ protected Void createContext(com.oracle.truffle.api.TruffleLanguage.Env env) {
841837
}
842838

843839
@Override
844-
protected CallTarget parse(final Source code, Node context, String... argumentNames) throws IOException {
840+
protected CallTarget parse(final Source code, Node context, String... argumentNames) {
845841
return Truffle.getRuntime().createCallTarget(new RootNode(TestIsNodeTaggedWith1Language.class, null, null) {
846842

847843
@Child private BaseNode base = InstrumentationTestLanguage.parse(code);

truffle/com.oracle.truffle.api.interop.java.test/src/com/oracle/truffle/api/interop/java/test/JavaFunctionTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.oracle.truffle.api.interop.java.JavaInterop;
2828
import com.oracle.truffle.api.vm.PolyglotEngine;
29-
import java.io.IOException;
3029
import java.util.Collections;
3130
import java.util.Comparator;
3231
import java.util.HashSet;
@@ -42,7 +41,7 @@ public class JavaFunctionTest {
4241
private PolyglotEngine engine;
4342

4443
@Test
45-
public void invokeRunnable() throws IOException {
44+
public void invokeRunnable() throws Exception {
4645
final boolean[] called = {false};
4746

4847
engine = PolyglotEngine.newBuilder().globalSymbol("test", JavaInterop.asTruffleFunction(Runnable.class, new Runnable() {
@@ -57,7 +56,7 @@ public void run() {
5756
}
5857

5958
@Test
60-
public void invokeIterable() throws IOException {
59+
public void invokeIterable() throws Exception {
6160
final boolean[] called = {false};
6261

6362
engine = PolyglotEngine.newBuilder().globalSymbol("test", JavaInterop.asTruffleFunction(Iterable.class, new Iterable<Object>() {
@@ -73,7 +72,7 @@ public Iterator<Object> iterator() {
7372
}
7473

7574
@Test
76-
public void invokeHashableInterface() throws IOException {
75+
public void invokeHashableInterface() throws Exception {
7776
final boolean[] called = {false};
7877

7978
engine = PolyglotEngine.newBuilder().globalSymbol("test", JavaInterop.asTruffleFunction(Hashable.class, new Hashable() {
@@ -89,7 +88,7 @@ public String name() {
8988
}
9089

9190
@Test
92-
public void invokeComparator() throws IOException {
91+
public void invokeComparator() throws Exception {
9392
final boolean[] called = {false};
9493

9594
engine = PolyglotEngine.newBuilder().globalSymbol("test", JavaInterop.asTruffleFunction(Comparator.class, new Comparator<Integer>() {

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/TestingLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ private TestingLanguage() {
3535
}
3636

3737
@Override
38-
protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
39-
throw new IOException();
38+
protected CallTarget parse(Source code, Node context, String... argumentNames) {
39+
throw new IllegalStateException();
4040
}
4141

4242
@Override

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/EngineSingleThreadedTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public void orderDispose() throws InterruptedException {
6767
}
6868

6969
@Test(expected = IllegalStateException.class)
70-
public void evalURI() throws IOException {
70+
public void evalURI() throws Exception {
7171
tvm.eval(Source.newBuilder(new File(".").toURI().toURL()).name("wrong.test").build());
7272
}
7373

7474
@Test(expected = IllegalStateException.class)
75-
public void evalString() throws IOException {
75+
public void evalString() {
7676
tvm.eval(Source.newBuilder("1 + 1").name("wrong.test").mimeType("text/javascript").build());
7777
}
7878

@@ -84,7 +84,7 @@ public void evalReader() throws IOException {
8484
}
8585

8686
@Test(expected = IllegalStateException.class)
87-
public void evalSource() throws IOException {
87+
public void evalSource() {
8888
tvm.eval(Source.newBuilder("").name("Empty").mimeType("text/plain").build());
8989
}
9090

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/EngineTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import static org.junit.Assert.assertNotEquals;
2727
import static org.junit.Assert.assertNotNull;
2828

29-
import java.io.IOException;
3029
import java.util.List;
3130

3231
import org.junit.Test;
@@ -89,8 +88,8 @@ public void testPassingThroughInteropException() throws Exception {
8988
try {
9089
PolyglotEngine.Value value = language1.eval(Source.newBuilder("throwInteropException").name("interopTest").mimeType("content/unknown").build());
9190
value.as(Object.class);
92-
} catch (IOException e) {
93-
if (e.getCause() instanceof InteropException) {
91+
} catch (Exception e) {
92+
if (e instanceof InteropException) {
9493
return;
9594
}
9695
Assert.fail(String.format("expected InteropException but was %s in %s", e.getCause(), e));
@@ -99,7 +98,7 @@ public void testPassingThroughInteropException() throws Exception {
9998
}
10099

101100
@Test
102-
public void checkCachingOfNodes() throws IOException {
101+
public void checkCachingOfNodes() {
103102
PolyglotEngine vm1 = createBuilder().build();
104103
register(vm1);
105104
PolyglotEngine vm2 = createBuilder().executor(Executors.newSingleThreadExecutor()).build();
@@ -170,7 +169,7 @@ public void wrappedAsArray() throws Exception {
170169
}
171170

172171
@Test
173-
public void engineConfigBasicAccess() throws IOException {
172+
public void engineConfigBasicAccess() {
174173
Builder builder = createBuilder();
175174
builder.config("application/x-test-import-export-1", "cmd-line-args", new String[]{"1", "2"});
176175
builder.config("application/x-test-import-export-2", "hello", "world");
@@ -199,7 +198,7 @@ public void engineConfigBasicAccess() throws IOException {
199198
}
200199

201200
@Test
202-
public void engineConfigShouldBeReadOnly() throws IOException {
201+
public void engineConfigShouldBeReadOnly() {
203202
Builder builder = createBuilder();
204203
builder.config("application/x-test-import-export-1", "cmd-line-args", new String[]{"1", "2"});
205204
builder.config("application/x-test-import-export-2", "hello", "world");
@@ -219,7 +218,7 @@ public void engineConfigShouldBeReadOnly() throws IOException {
219218
}
220219

221220
@Test
222-
public void secondValueWins() throws IOException {
221+
public void secondValueWins() {
223222
Builder builder = createBuilder();
224223
builder.config("application/x-test-import-export-2", "hello", "truffle");
225224
builder.config("application/x-test-import-export-2", "hello", "world");
@@ -232,7 +231,7 @@ public void secondValueWins() throws IOException {
232231
}
233232

234233
@Test
235-
public void secondValueWins2() throws IOException {
234+
public void secondValueWins2() {
236235
Builder builder = createBuilder();
237236
builder.config("application/x-test-import-export-2", "hello", "world");
238237
builder.config("application/x-test-import-export-2", "hello", "truffle");
@@ -245,7 +244,7 @@ public void secondValueWins2() throws IOException {
245244
}
246245

247246
@Test
248-
public void altValueWins() throws IOException {
247+
public void altValueWins() {
249248
Builder builder = createBuilder();
250249
builder.config(L1, "hello", "truffle");
251250
builder.config(L1_ALT, "hello", "world");
@@ -258,7 +257,7 @@ public void altValueWins() throws IOException {
258257
}
259258

260259
@Test
261-
public void altValueWins2() throws IOException {
260+
public void altValueWins2() {
262261
Builder builder = createBuilder();
263262
builder.config(L1_ALT, "hello", "truffle");
264263
builder.config(L1, "hello", "world");
@@ -271,7 +270,7 @@ public void altValueWins2() throws IOException {
271270
}
272271

273272
@Test
274-
public void configIsNeverNull() throws IOException {
273+
public void configIsNeverNull() {
275274
Builder builder = createBuilder();
276275
PolyglotEngine vm = builder.build();
277276
register(vm);
@@ -286,7 +285,7 @@ static class YourLang {
286285
}
287286

288287
@Test
289-
public void exampleOfConfiguration() throws IOException {
288+
public void exampleOfConfiguration() {
290289
// @formatter:off
291290
String[] args = {"--kernel", "Kernel.som", "--instrument", "dyn-metrics"};
292291
Builder builder = PolyglotEngine.newBuilder();

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/ExceptionDuringParsingTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import static org.junit.Assert.assertTrue;
2929
import static org.junit.Assert.fail;
3030

31-
import java.io.IOException;
32-
3331
import org.junit.After;
3432
import org.junit.Before;
3533
import org.junit.Test;
@@ -57,7 +55,7 @@ public void canGetAccessToOwnLanguageInstance() throws Exception {
5755
try {
5856
vm.eval(src);
5957
fail("Exception thrown");
60-
} catch (IOException ex) {
58+
} catch (Exception ex) {
6159
assertEquals(ex.getMessage(), "No, no, no!");
6260
}
6361

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/GlobalSymbolTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.junit.Assert.assertNotNull;
2929
import static org.junit.Assert.assertTrue;
3030

31-
import java.io.IOException;
3231
import java.util.List;
3332

3433
import org.junit.After;
@@ -49,7 +48,7 @@ public void after() {
4948
}
5049

5150
@Test
52-
public void globalSymbolFoundByLanguage() throws IOException {
51+
public void globalSymbolFoundByLanguage() {
5352
vm = createEngineBuilder().globalSymbol("ahoj", "42").build();
5453
// @formatter:off
5554
Object ret = vm.eval(Source.newBuilder("return=ahoj").name("Return").mimeType(L3).build()
@@ -59,7 +58,7 @@ public void globalSymbolFoundByLanguage() throws IOException {
5958
}
6059

6160
@Test
62-
public void globalSymbolFoundByVMUser() throws IOException {
61+
public void globalSymbolFoundByVMUser() {
6362
vm = createEngineBuilder().globalSymbol("ahoj", "42").build();
6463
PolyglotEngine.Value ret = vm.findGlobalSymbol("ahoj");
6564
assertNotNull("Symbol found", ret);
@@ -71,7 +70,7 @@ protected PolyglotEngine.Builder createEngineBuilder() {
7170
}
7271

7372
@Test
74-
public void passingArray() throws IOException {
73+
public void passingArray() {
7574
vm = createEngineBuilder().globalSymbol("arguments", new Object[]{"one", "two", "three"}).build();
7675
PolyglotEngine.Value value = vm.findGlobalSymbol("arguments");
7776
assertFalse("Not instance of array", value.get() instanceof Object[]);

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/ImplicitExplicitExportTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void cleanThread() {
7676
}
7777

7878
@Test
79-
public void explicitExportFound() throws IOException {
79+
public void explicitExportFound() {
8080
// @formatter:off
8181
vm.eval(Source.newBuilder("explicit.ahoj=42").name("Fourty two").mimeType(L1).build());
8282
Object ret = vm.eval(Source.newBuilder("return=ahoj").name("Return").mimeType(L3).build()
@@ -86,7 +86,7 @@ public void explicitExportFound() throws IOException {
8686
}
8787

8888
@Test
89-
public void implicitExportFound() throws IOException {
89+
public void implicitExportFound() {
9090
// @formatter:off
9191
vm.eval(Source.newBuilder("implicit.ahoj=42").name("Fourty two").mimeType(L1).build()
9292
);
@@ -97,7 +97,7 @@ public void implicitExportFound() throws IOException {
9797
}
9898

9999
@Test
100-
public void explicitExportPreferred2() throws IOException {
100+
public void explicitExportPreferred2() {
101101
// @formatter:off
102102
vm.eval(Source.newBuilder("implicit.ahoj=42").name("Fourty two").mimeType(L1).build()
103103
);
@@ -111,7 +111,7 @@ public void explicitExportPreferred2() throws IOException {
111111
}
112112

113113
@Test
114-
public void explicitExportPreferred1() throws IOException {
114+
public void explicitExportPreferred1() {
115115
// @formatter:off
116116
vm.eval(Source.newBuilder("explicit.ahoj=43").name("Fourty three").mimeType(L1).build()
117117
);
@@ -191,7 +191,7 @@ protected boolean isObjectOfLanguage(Object object) {
191191
}
192192

193193
@Override
194-
protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException {
194+
protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) {
195195
return null;
196196
}
197197

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/InitializationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import static org.junit.Assert.assertNull;
2626

27-
import java.io.IOException;
28-
2927
import org.junit.After;
3028

3129
import com.oracle.truffle.api.CallTarget;
@@ -138,7 +136,7 @@ protected Object createContext(Env env) {
138136
}
139137

140138
@Override
141-
protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
139+
protected CallTarget parse(Source code, Node context, String... argumentNames) {
142140
return Truffle.getRuntime().createCallTarget(new MMRootNode(code.createSection("1st line", 1)));
143141
}
144142

truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/IsMimeTypeSupportedTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import static org.junit.Assert.assertEquals;
2626

27-
import java.io.IOException;
28-
2927
import org.junit.Test;
3028

3129
import com.oracle.truffle.api.source.Source;
@@ -48,7 +46,7 @@ public void dispose() {
4846
}
4947

5048
@Test
51-
public void isMimeSupported() throws IOException {
49+
public void isMimeSupported() {
5250
assertEquals(true, vm.eval(Source.newBuilder(MIME_TYPE).name("supported").mimeType(MIME_TYPE).build()).as(Boolean.class));
5351
assertEquals(false, vm.eval(Source.newBuilder("application/x-this-language-does-not-exist").name("unsupported").mimeType(MIME_TYPE).build()).as(Boolean.class));
5452
}

0 commit comments

Comments
 (0)