11/*
2- * Copyright (c) 2024, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2024, 2026 , 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
2323
2424/*
2525 * @test
26- * @bug 8350704
26+ * @bug 8350704 8381377
2727 * @summary Test behaviors with various bad EnclosingMethod attribute
2828 * @library /test/lib
2929 * @run junit BadEnclosingMethodTest
@@ -111,7 +111,7 @@ void testMalformedTypes() throws Exception {
111111 * valid, but refers to a class or interface that cannot be found.
112112 */
113113 @ Test
114- void testAbsentMethods () throws Exception {
114+ void testAbsentTypeInMethods () throws Exception {
115115 var absentMethodType = loadTestClass ("methodName" , "(Ldoes/not/Exist;)V" );
116116 var ex = assertThrows (TypeNotPresentException .class ,
117117 absentMethodType ::getEnclosingMethod );
@@ -122,8 +122,29 @@ void testAbsentMethods() throws Exception {
122122 absentConstructorType ::getEnclosingConstructor );
123123 assertEquals ("does.not.Exist" , ex .typeName ());
124124 }
125+
126+ /**
127+ * Test reflective behaviors when the EnclosingMethod attribute uses valid
128+ * class and method names and types, but the method does not exist.
129+ */
130+ @ Test
131+ void testAbsentMethods () throws Exception {
132+ var absentMethodType = loadTestClass ("work" , "(I)V" );
133+ var ex = assertThrows (NoSuchMethodError .class ,
134+ absentMethodType ::getEnclosingMethod );
135+ var message = ex .getMessage ();
136+ assertTrue (message .contains ("Encloser.work(I)V" ));
137+
138+ var absentConstructorType = loadTestClass (INIT_NAME , "(I)V" );
139+ ex = assertThrows (NoSuchMethodError .class ,
140+ absentConstructorType ::getEnclosingConstructor );
141+ message = ex .getMessage ();
142+ assertTrue (message .contains ("Encloser.<init>(I)V" ));
143+ }
144+
125145}
126146
147+ // These guys are compiled to serve as templates for bytecode transformation
127148class Encloser {
128149 private static void work () {
129150 class Enclosed {
0 commit comments