Skip to content

Commit

Permalink
fix: Gracefully handle missing '[' in multianewarray desc
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Aug 14, 2024
1 parent 06e5b2c commit f61f0e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void setErrorCollector(ErrorCollector errorCollector) {
* @param message
* Warning message content.
*/
protected void warn(@NotNull CodeElement element, @NotNull String message) {
public void warn(@NotNull CodeElement element, @NotNull String message) {
if (errorCollector == null) return;
ASTInstruction ast = getCodeToAstMap().get(element);
if (ast != null) errorCollector.addWarn(message, ast.location());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,17 @@ public void visitInvokeDynamicInsn(ASTIdentifier name, ASTIdentifier descriptor,

@Override
public void visitMultiANewArrayInsn(ASTIdentifier descriptor, ASTNumber numDimensions) {
ArrayType arrayType = Types.arrayTypeFromDescriptor(descriptor.literal());
int dimSize = numDimensions.asInt();
add(new AllocateMultiDimArrayInstruction(arrayType, dimSize));
String literal = descriptor.literal();
Type literalType = Types.typeFromDescriptor(literal);
if (literalType instanceof ArrayType literalArrayType) {
add(new AllocateMultiDimArrayInstruction(literalArrayType, dimSize));
} else {
ArrayType arrayType = Types.arrayType((ClassType) literalType);
var insn = new AllocateMultiDimArrayInstruction(arrayType, dimSize);
add(insn);
analysisEngine.warn(insn, "Expected array type, got class name");
}
}

@Override
Expand Down

0 comments on commit f61f0e5

Please sign in to comment.