Skip to content

Commit 56c30fc

Browse files
author
duke
committed
Backport 1d53ac30f1db88df9a97b63b3ff56d26975d3a57
1 parent f672a4c commit 56c30fc

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/java.base/share/classes/sun/invoke/util/BytecodeDescriptor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -96,8 +96,15 @@ private static Class<?> parseSig(String str, int[] i, int end, ClassLoader loade
9696
}
9797
} else if (c == '[') {
9898
Class<?> t = parseSig(str, i, end, loader);
99-
if (t != null)
100-
t = t.arrayType();
99+
if (t != null) {
100+
try {
101+
t = t.arrayType();
102+
} catch (UnsupportedOperationException ex) {
103+
// Bad arrays, such as [V or more than 255 dims
104+
// We have a more informative IAE
105+
return null;
106+
}
107+
}
101108
return t;
102109
} else {
103110
return Wrapper.forBasicType(c).primitiveType();

test/jdk/java/lang/invoke/MethodTypeTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,6 +22,7 @@
2222
*/
2323

2424
/* @test
25+
* @bug 8366028
2526
* @summary unit tests for java.lang.invoke.MethodType
2627
* @compile MethodTypeTest.java
2728
* @run testng/othervm test.java.lang.invoke.MethodTypeTest
@@ -35,6 +36,8 @@
3536

3637
import java.util.*;
3738
import org.testng.*;
39+
40+
import static org.testng.Assert.assertThrows;
3841
import static org.testng.AssertJUnit.*;
3942
import org.testng.annotations.*;
4043

@@ -218,6 +221,24 @@ private static String concat(Object... parts) {
218221
return sb.toString().replace('.', '/');
219222
}
220223

224+
@DataProvider(name = "badMethodDescriptorStrings")
225+
public String[] badMethodDescriptorStrings() {
226+
return new String[] {
227+
"(I)",
228+
"(V)V",
229+
"([V)V",
230+
"(" + "[".repeat(256) + "J)I",
231+
"(java/lang/Object)V",
232+
"()java/lang/Object",
233+
};
234+
}
235+
236+
// JDK-8366028
237+
@Test(dataProvider = "badMethodDescriptorStrings", expectedExceptions = IllegalArgumentException.class)
238+
public void testFromMethodDescriptorStringNegatives(String desc) {
239+
MethodType.fromMethodDescriptorString(desc, null);
240+
}
241+
221242
@Test
222243
public void testHasPrimitives() {
223244
System.out.println("hasPrimitives");

0 commit comments

Comments
 (0)