swiftlang / swiftlang/swift-java
Throwable CustomStringConvertible is risking infinite recursion
Open
Nobody has claimed this yet.
bug
mode:jni
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
Happened during an import of all of apache commons csv:
JAVASWIFT="../../.build/debug/Java2Swift"
MODULE_NAME="JavaCommonsCSV"
MODULE_CONFIG_DIR=$(pwd)/Sources/$MODULE_NAME/
MODULE_CONFIG_PATH="$MODULE_CONFIG_DIR/swift-java.config"
### 1) downloads all the dependencies
"$JAVASWIFT" --fetch "$MODULE_CONFIG_DIR/swift-java.config" \
--module-name "$MODULE_NAME" \
--output-directory "$MODULE_CONFIG_DIR"
### 2) extract the config for the fetched dependency
DEP_JAR_CP=$(jq .classpath "$MODULE_CONFIG_PATH")
DEP_JAR_CP=$(echo "$DEP_JAR_CP" | tr -d '"') # trim the "..."
# shellcheck disable=SC2086
"$JAVASWIFT" --jar $DEP_JAR_CP \
--module-name "$MODULE_NAME" \
--java-package-filter org.apache.commons \
--existing-config amend
### 3) make wrappers for the module
swift run
It looks like infinite recursion of custom string repr of a throwable:
Current thread (0x0000000124008200): JavaThread "main" [_thread_in_vm, id=259, stack(0x000000016d1c4000,0x000000016d9c0000) (8176K)]
Stack: [0x000000016d1c4000,0x000000016d9c0000], sp=0x000000016d1cfbb0, free space=46k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.dylib+0xa7e7a0] VMError::report_and_die(int, char const*, char const*, char*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x53c (stackOverflow.cpp:239)
V [libjvm.dylib+0xa7ef14] VMError::report_and_die(Thread*, unsigned int, unsigned char*, void*, void*)+0x0
V [libjvm.dylib+0x2d8ce4] print_error_for_unit_test(char const*, char const*, char*)+0x0
V [libjvm.dylib+0x970a40] StackOverflow::reguard_stack(unsigned char*)+0x184
V [libjvm.dylib+0x970b1c] StackOverflow::reguard_stack_if_needed()+0x2c
V [libjvm.dylib+0x4a5120] JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x1a0
V [libjvm.dylib+0x5177d8] jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, JavaThread*)+0x3e0
V [libjvm.dylib+0x51b804] jni_CallObjectMethodA+0x118
C [Java2Swift-tool+0x16ee04] $sSpySPySo19JNINativeInterface_VGSgGSgs13OpaquePointerVSgAISPySo6jvalueVGSgAIIetCyyyyd_Af2imIIegyyyyd_TR+0xc
C [Java2Swift-tool+0x16ee50] $sSpySPySo19JNINativeInterface_VGSgGSgs13OpaquePointerVSgAISPySo6jvalueVGSgAIIegyyyyd_Ae2hmIIegyyyyd_TR+0x14
C [Java2Swift-tool+0x170444] $sSpySPySo19JNINativeInterface_VGSgGs13OpaquePointerVAGSPySo6jvalueVGSgAGSgIegyyyyd_Ae2gkLIegyyyyr_TR+0x1c
C [Java2Swift-tool+0x155504] $s7JavaKit03AnyA6ObjectPAAE14javaMethodCall2in4this6method4argsqd_0_SpySPySo19JNINativeInterface_VGSgG_s13OpaquePointerVAOqd__qd__QptKRvd__AA0A5ValueRd__AaPRd_0_r0_lFZ7JNITypeQyd_0_yXEfU_+0x254
C [Java2Swift-tool+0x155688] $s7JavaKit03AnyA6ObjectPAAE14javaMethodCall2in4this6method4argsqd_0_SpySPySo19JNINativeInterface_VGSgG_s13OpaquePointerVAOqd__qd__QptKRvd__AA0A5ValueRd__AaPRd_0_r0_lFZ7JNITypeQyd_0_yXEfU_TA+0x74
C [Java2Swift-tool+0x100e78] $sSp7JavaKitSPySo19JNINativeInterface_VGSgRszlE24translatingJNIExceptions4bodyqd__qd__yKXE_tKlF+0xc0
C [Java2Swift-tool+0x155154] $s7JavaKit03AnyA6ObjectPAAE14javaMethodCall2in4this6method4argsqd_0_SpySPySo19JNINativeInterface_VGSgG_s13OpaquePointerVAOqd__qd__QptKRvd__AA0A5ValueRd__AaPRd_0_r0_lFZ+0x63c
C [Java2Swift-tool+0x155a98] $s7JavaKit03AnyA6ObjectPAAE14javaMethodCall6method4argsqd_0_s13OpaquePointerV_qd__qd__QptKRvd__AA0A5ValueRd__AaIRd_0_r0_lF+0x400
C [Java2Swift-tool+0x15637c] $s7JavaKit03AnyA6ObjectPAAE07dynamicA10MethodCall10methodName9arguments10resultTypeqd_0_SS_qd__qd__Qpqd_0_mtKRvd__AA0A5ValueRd__AaHRd_0_r0_lF+0x810
C [Java2Swift-tool+0x18a778] $s7JavaKit9ThrowableC10getMessageSSyF+0xb0
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
C [libswiftCore.dylib+0xefc00] $ss20_debugPrint_unlockedyyx_q_zts16TextOutputStreamR_r0_lF+0x1fc
C [libswiftCore.dylib+0xaf0fc] swift_unexpectedError+0x134
C [Java2Swift-tool+0x18a7e8] $s7JavaKit9ThrowableC10getMessageSSyF+0x120
C [Java2Swift-tool+0x189374] $s7JavaKit9ThrowableC11descriptionSSvg+0x24
C [Java2Swift-tool+0x1893e4] $s7JavaKit9ThrowableCs23CustomStringConvertibleAAsADP11descriptionSSvgTW+0x14
...<more frames>...
Lock stack of current Java thread (top to bottom):
--------------- P R O C E S S ---------------
Threads class SMR info:
_java_thread_list=0x000060000329e060, length=10, elements={
0x0000000124008200, 0x000000013400fe00, 0x000000010680b400, 0x000000010680bc00,
0x0000000134013200, 0x000000013400d000, 0x000000012400c000, 0x000000013402a200,
0x0000000124809400, 0x000000010481ae00
}
Java Threads: ( => current thread )
=>0x0000000124008200 JavaThread "main" [_thread_in_vm, id=259, stack(0x000000016d1c4000,0x000000016d9c0000) (8176K)]
0x000000013400fe00 JavaThread "Reference Handler" daemon [_thread_blocked, id=30979, stack(0x000000017e930000,0x000000017eb33000) (2060K)]
0x000000010680b400 JavaThread "Finalizer" daemon [_thread_blocked, id=30467, stack(0x000000017eb3c000,0x000000017ed3f000) (2060K)]
0x000000010680bc00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=23555, stack(0x000000017ed48000,0x000000017ef4b000) (2060K)]
0x0000000134013200 JavaThread "Service Thread" daemon [_thread_blocked, id=23811, stack(0x000000017ef54000,0x000000017f157000) (2060K)]
0x000000013400d000 JavaThread "Monitor Deflation Thread" daemon [_thread_blocked, id=24323, stack(0x000000017f160000,0x000000017f363000) (2060K)]
0x000000012400c000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=29699, stack(0x000000017f36c000,0x000000017f56f000) (2060K)]
0x000000013402a200 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=24835, stack(0x000000017f578000,0x000000017f77b000) (2060K)]
0x0000000124809400 JavaThread "Notification Thread" daemon [_thread_blocked, id=25091, stack(0x000000017f784000,0x000000017f987000) (2060K)]
0x000000010481ae00 JavaThread "Common-Cleaner" daemon [_thread_blocked, id=25347, stack(0x000000017f990000,0x000000017fb93000) (2060K)]
Total: 10
Other Threads:
0x0000000123f0c8d0 VMThread "VM Thread" [id=21251, stack(0x000000017e60c000,0x000000017e80f000) (2060K)]
0x0000000123f09d30 WatcherThread "VM Periodic Task Thread" [id=13571, stack(0x000000017e400000,0x000000017e603000) (2060K)]
0x0000000123f04560 WorkerThread "GC Thread#0" [id=11267, stack(0x000000017d9c4000,0x000000017dbc7000) (2060K)]
0x0000000123f04eb0 ConcurrentGCThread "G1 Main Marker" [id=15363, stack(0x000000017dbd0000,0x000000017ddd3000) (2060K)]
0x0000000123f05830 WorkerThread "G1 Conc#0" [id=11779, stack(0x000000017dddc000,0x000000017dfdf000) (2060K)]
0x000000012487f600 ConcurrentGCThread "G1 Refine#0" [id=12291, stack(0x000000017dfe8000,0x000000017e1eb000) (2060K)]
0x0000000123f07ed0 ConcurrentGCThread "G1 Service" [id=12547, stack(0x000000017e1f4000,0x000000017e3f7000) (2060K)]
Total: 7
Threads with active compile tasks:
Total: 0
VM state: not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
OutOfMemory and StackOverflow Exception counts:
StackOverflowErrors=129
LinkageErrors=2
Heap address: 0x0000000400000000, size: 16384 MB, Compressed Oops mode: Zero based, Oop shift amount: 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report centers on JavaKit.Throwable's getMessage and CustomStringConvertible description during the Java2Swift import flow; start by tracing that call path and reproducing the Apache Commons CSV import shown. Done means the throwable can be inspected without recursive description calls and the import no longer overflows the stack.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100