@@ -508,34 +508,45 @@ class TypeScriptGenerator(
508508
509509
510510 private fun constructorsOf (klass : KClass <* >): String = try {
511- klass.constructors.joinToString(" " ) { constructor ->
512- val parameters = constructor .parameters
513- .joinToString(" , " ) { param ->
514- val paramType = pipeline.transformFunctionParameterType(param.type, param, constructor , klass)
515- " ${param.name} : ${formatKType(paramType).formatWithoutParenthesis()} "
511+ // Wrap the entire reflection process in a try-catch
512+ try {
513+ // Force early class loading to trigger any NoClassDefFoundError
514+ klass.java.declaredConstructors
516515
516+ klass.constructors.joinToString(" " ) { constructor ->
517+ val parameters = constructor .parameters
518+ .joinToString(" , " ) { param ->
519+ val paramType =
520+ pipeline.transformFunctionParameterType(param.type, param, constructor , klass)
521+ " ${param.name} : ${formatKType(paramType).formatWithoutParenthesis()} "
522+ }
523+ val visibility = when (constructor .visibility) {
524+ KVisibility .PRIVATE -> " // private "
525+ KVisibility .PROTECTED -> " protected "
526+ KVisibility .PUBLIC -> " "
527+ KVisibility .INTERNAL -> " "
528+ else -> " "
517529 }
518- val visibility = when (constructor .visibility) {
519- KVisibility .PRIVATE -> " // private "
520- KVisibility .PROTECTED -> " protected "
521- KVisibility .PUBLIC -> " "
522- KVisibility .INTERNAL -> " "
523- else -> " "
530+ " ${visibility} constructor($parameters )\n "
531+ .commentIfInvalid()
524532 }
525- " ${visibility} constructor($parameters )\n "
526- .commentIfInvalid()
533+ } catch (e: Throwable ) {
534+ // This will catch all exceptions including NoClassDefFoundError and lower-level
535+ // reflection errors like the one you're experiencing
536+ println (" Unable to process constructors for ${klass.qualifiedName} : ${e.javaClass.name} : ${e.message} " )
537+ " "
527538 }
528539 } catch (exception: kotlin.reflect.jvm.internal.KotlinReflectionInternalError ) {
529- print (exception.toString())
540+ println (exception.toString())
530541 " "
531542 } catch (exception: java.lang.IllegalArgumentException ) {
532- print (exception.toString())
543+ println (exception.toString())
533544 " "
534545 } catch (exception: NoClassDefFoundError ) {
535- print (" Missing dependency: ${exception.message} " )
546+ println (" Missing dependency: ${exception.message} " )
536547 " " // Return empty string when dependency is missing
537548 } catch (exception: IllegalStateException ) {
538- print (" Likely unable to infer accessibility: ${exception.message} " )
549+ println (" Likely unable to infer accessibility: ${exception.message} " )
539550 " "
540551 }
541552
0 commit comments