< prev index next >

test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java

Print this page

  1 /*
  2  * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */

289                 assertFalse(hc.isEnum());
290                 assertFalse(hc.isAnnotation());
291                 assertFalse(hc.isInterface());
292                 break;
293             case ACC_ABSTRACT|ACC_INTERFACE:
294                 assertFalse(hc.isSynthetic());
295                 assertFalse(hc.isEnum());
296                 assertFalse(hc.isAnnotation());
297                 assertTrue(hc.isInterface());
298                 break;
299             case ACC_ANNOTATION|ACC_ABSTRACT|ACC_INTERFACE:
300                 assertFalse(hc.isSynthetic());
301                 assertFalse(hc.isEnum());
302                 assertTrue(hc.isAnnotation());
303                 assertTrue(hc.isInterface());
304                 break;
305             default:
306                 throw new IllegalArgumentException("unexpected access flag: " + accessFlags);
307         }
308         assertTrue(hc.isHidden());
309         assertEquals(hc.getModifiers(), ACC_PUBLIC | accessFlags);

310         assertFalse(hc.isLocalClass());
311         assertFalse(hc.isMemberClass());
312         assertFalse(hc.isAnonymousClass());
313         assertFalse(hc.isArray());
314     }
315 
316     // These class files can't be defined as hidden classes
317     private static Object[][] cantBeHiddenClasses() {
318         return new Object[][] {
319                 // a hidden class can't be a field's declaring type
320                 // enum class with static final HiddenEnum[] $VALUES:
321                 new Object[] { "HiddenEnum" },
322                 // supertype of this class is a hidden class
323                 new Object[] { "HiddenSuper" },
324                 // a record class whose equals(HiddenRecord, Object) method
325                 // refers to a hidden class in the parameter type and fails
326                 // verification.  Perhaps this method signature should be reconsidered.
327                 new Object[] { "HiddenRecord" },
328         };
329     }

  1 /*
  2  * Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */

289                 assertFalse(hc.isEnum());
290                 assertFalse(hc.isAnnotation());
291                 assertFalse(hc.isInterface());
292                 break;
293             case ACC_ABSTRACT|ACC_INTERFACE:
294                 assertFalse(hc.isSynthetic());
295                 assertFalse(hc.isEnum());
296                 assertFalse(hc.isAnnotation());
297                 assertTrue(hc.isInterface());
298                 break;
299             case ACC_ANNOTATION|ACC_ABSTRACT|ACC_INTERFACE:
300                 assertFalse(hc.isSynthetic());
301                 assertFalse(hc.isEnum());
302                 assertTrue(hc.isAnnotation());
303                 assertTrue(hc.isInterface());
304                 break;
305             default:
306                 throw new IllegalArgumentException("unexpected access flag: " + accessFlags);
307         }
308         assertTrue(hc.isHidden());
309         // ACC_SUPER bit may appear spuriously if preview is enabled
310         assertEquals(hc.getModifiers() & (~ACC_SUPER), (ACC_PUBLIC | accessFlags));
311         assertFalse(hc.isLocalClass());
312         assertFalse(hc.isMemberClass());
313         assertFalse(hc.isAnonymousClass());
314         assertFalse(hc.isArray());
315     }
316 
317     // These class files can't be defined as hidden classes
318     private static Object[][] cantBeHiddenClasses() {
319         return new Object[][] {
320                 // a hidden class can't be a field's declaring type
321                 // enum class with static final HiddenEnum[] $VALUES:
322                 new Object[] { "HiddenEnum" },
323                 // supertype of this class is a hidden class
324                 new Object[] { "HiddenSuper" },
325                 // a record class whose equals(HiddenRecord, Object) method
326                 // refers to a hidden class in the parameter type and fails
327                 // verification.  Perhaps this method signature should be reconsidered.
328                 new Object[] { "HiddenRecord" },
329         };
330     }
< prev index next >