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)}`, + ); } } }