Skip to content

Commit aef0c02

Browse files
committed
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.
1 parent c482bcd commit aef0c02

File tree

1 file changed

+9
-9
lines changed
  • packages/jsii-pacmak/lib/targets

1 file changed

+9
-9
lines changed

packages/jsii-pacmak/lib/targets/java.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,26 +1603,26 @@ class JavaGenerator extends Generator {
16031603
) {
16041604
if (spec.isUnionTypeReference(type)) {
16051605
validateTypeUnion.call(this, value, descr, type, parameterName);
1606-
} else {
1607-
const collectionType = type as spec.CollectionTypeReference;
1608-
if (collectionType.collection.kind === spec.CollectionKind.Array) {
1609-
validateArray.call(
1606+
} else if (spec.isCollectionTypeReference(type)) {
1607+
switch (type.collection.kind) {
1608+
case spec.CollectionKind.Array:
1609+
return validateArray.call(
16101610
this,
16111611
value,
16121612
descr,
1613-
collectionType.collection.elementtype,
1613+
type.collection.elementtype,
16141614
parameterName,
16151615
isRawArray,
16161616
);
1617-
} else if (collectionType.collection.kind === spec.CollectionKind.Map) {
1618-
validateMap.call(
1617+
case spec.CollectionKind.Map:
1618+
return validateMap.call(
16191619
this,
16201620
value,
16211621
descr,
1622-
collectionType.collection.elementtype,
1622+
type.collection.elementtype,
16231623
parameterName,
16241624
);
1625-
} else {
1625+
default:
16261626
throw new Error(
16271627
`Unhandled collection kind: ${spec.describeTypeReference(type)}`,
16281628
);

0 commit comments

Comments
 (0)