Skip to content

Commit

Permalink
fix: LambdaMetafactory short descriptor being wrongly verified
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Feb 4, 2024
1 parent 5d7601b commit 293be33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,19 @@ public static Constant fromConstant(ASTElement element) {
assert identifier.content() != null;
char first = identifier.content().charAt(0);
yield switch (first) {
case 'L' -> new OfType(Types.instanceTypeFromDescriptor(identifier.literal()));
case 'L' -> {
// if last is `;` then it's a class type, if not could be a short handle
char last = identifier.content().charAt(identifier.content().length() - 1);
if(last == ';') {
yield new OfType(Types.instanceTypeFromDescriptor(identifier.literal()));
} else {
Handle handle = Handle.HANDLE_SHORTCUTS.get(identifier.literal());
if (handle != null) {
yield new OfMethodHandle(methodHandleFromHandle(handle));
}
throw new IllegalStateException("Unexpected value: " + first);
}
}
case '(' -> new OfType(Types.methodType(identifier.literal()));
case '[' -> new OfType(Types.arrayTypeFromDescriptor(identifier.literal()));
default -> switch (identifier.literal().toLowerCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ public static void verifyConstant(ASTProcessor.ParserContext context, ASTElement
case IDENTIFIER -> {
char first = element.content().charAt(0);
boolean valid = switch (first) {
case 'L', '[' -> DescriptorUtil.isValidFieldDescriptor(element.content());
case 'L', '[' -> {
// if last is `;` then it's a class type, if not could be a short handle
char last = element.content().charAt(element.content().length() - 1);
if (last == ';') {
yield DescriptorUtil.isValidFieldDescriptor(element.content());
} else {
Handle handle = Handle.HANDLE_SHORTCUTS.get(element.content());
if (handle == null) {
context.throwUnexpectedElementError("class, method or array descriptor", element);
}
yield true;
}
}
case '(' -> DescriptorUtil.isValidMethodDescriptor(element.content());
default -> {
// maybe its a number handle
Expand Down

0 comments on commit 293be33

Please sign in to comment.