From 1fd58db1e94a0024d173d53597416f1d2a2fa941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A7=91=F0=9F=8F=BB=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier?= Date: Tue, 30 Aug 2022 12:49:41 +0200 Subject: [PATCH] fix(pacmak): crash when generating java code A missing condition in the code generator could have resulted in attempting to read a property on undefined, resulting in a crash. --- packages/jsii-pacmak/lib/targets/java.ts | 46 ++++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/java.ts b/packages/jsii-pacmak/lib/targets/java.ts index e328e5568c..24906ba832 100644 --- a/packages/jsii-pacmak/lib/targets/java.ts +++ b/packages/jsii-pacmak/lib/targets/java.ts @@ -1603,29 +1603,29 @@ class JavaGenerator extends Generator { ) { if (spec.isUnionTypeReference(type)) { validateTypeUnion.call(this, value, descr, type, parameterName); - } else { - const collectionType = type as spec.CollectionTypeReference; - if (collectionType.collection.kind === spec.CollectionKind.Array) { - validateArray.call( - this, - value, - descr, - collectionType.collection.elementtype, - parameterName, - isRawArray, - ); - } else if (collectionType.collection.kind === spec.CollectionKind.Map) { - validateMap.call( - this, - value, - descr, - collectionType.collection.elementtype, - parameterName, - ); - } else { - throw new Error( - `Unhandled collection kind: ${spec.describeTypeReference(type)}`, - ); + } else if (spec.isCollectionTypeReference(type)) { + switch (type.collection.kind) { + case spec.CollectionKind.Array: + return validateArray.call( + this, + value, + descr, + type.collection.elementtype, + parameterName, + isRawArray, + ); + case spec.CollectionKind.Map: + return validateMap.call( + this, + value, + descr, + type.collection.elementtype, + parameterName, + ); + default: + throw new Error( + `Unhandled collection kind: ${spec.describeTypeReference(type)}`, + ); } } }