Skip to content

Commit 92fc134

Browse files
committed
Fix exception hiding in str.join
1 parent 5e9df0c commit 92fc134

File tree

1 file changed

+7
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+7
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringNodes.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,20 @@ static String doGeneric(VirtualFrame frame, String string, Object iterable,
310310
@Cached IsBuiltinClassProfile errorProfile1,
311311
@Cached IsBuiltinClassProfile errorProfile2,
312312
@Cached CastToJavaStringNode castStrNode) {
313-
313+
Object iterator;
314+
try {
315+
iterator = lib.getIteratorWithFrame(iterable, frame);
316+
} catch (PException e) {
317+
e.expect(PythonBuiltinClassType.TypeError, errorProfile0);
318+
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_JOIN_ITERABLE);
319+
}
314320
try {
315-
Object iterator = lib.getIteratorWithFrame(iterable, frame);
316321
StringBuilder str = new StringBuilder();
317322
try {
318323
append(str, checkItem(nextNode.execute(frame, iterator), 0, castStrNode, raise));
319324
} catch (PException e) {
320325
e.expectStopIteration(errorProfile1);
321326
return "";
322-
323327
}
324328
int i = 1;
325329
while (true) {
@@ -333,9 +337,6 @@ static String doGeneric(VirtualFrame frame, String string, Object iterable,
333337
append(str, string);
334338
append(str, checkItem(value, i++, castStrNode, raise));
335339
}
336-
} catch (PException e) {
337-
e.expect(PythonBuiltinClassType.TypeError, errorProfile0);
338-
throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.CAN_ONLY_JOIN_ITERABLE);
339340
} catch (OutOfMemoryError e) {
340341
throw raise.raise(MemoryError);
341342
}

0 commit comments

Comments
 (0)