< prev index next >
test/jdk/java/lang/reflect/Nestmates/TestReflectionAPI.java
Print this page
rev 59275 : [mq]: v1
*** 1,7 ****
/*
! * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 174,229 ****
new Class<?>[] { HostWithDuplicateMembers.class,
HostWithDuplicateMembers.Member1.class,
HostWithDuplicateMembers.Member2.class },
true);
! // Hosts with "bad" members
Class<?>[] bad = {
HostOfMemberNoHost.class,
HostOfMemberMissingHost.class,
HostOfMemberNotOurHost.class,
HostOfMemberNotInstanceHost.class,
HostOfMemberMalformedHost.class,
};
! Class<?>[] exceptions = {
! IncompatibleClassChangeError.class,
! NoClassDefFoundError.class,
! IncompatibleClassChangeError.class,
! IncompatibleClassChangeError.class,
! ClassFormatError.class,
! };
! String[] messages = {
! "Nest member HostOfMemberNoHost$MemberNoHost in HostOfMemberNoHost " +
! "declares a different nest host of HostOfMemberNoHost$MemberNoHost",
! "Unable to load nest-host class (NestHost) of " +
! "HostOfMemberMissingHost$MemberMissingHost",
! "Type HostOfMemberNotOurHost$MemberNotOurHost (loader: 'app') is not a nest member " +
! "of InvalidNestHost (loader: 'app'): current type is not listed as a nest member",
! "Type HostOfMemberNotInstanceHost$MemberNotInstanceHost (loader: 'app') is not a nest " +
! "member of [LInvalidNestHost; (loader: 'app'): current type is not listed as a nest member",
! "Incompatible magic value 3735928559 in class file MalformedHost",
! };
! for (int i = 0; i < bad.length; i++) {
! try {
! bad[i].getNestMembers();
! throw new Error("getNestMembers() succeeded for class " +
! bad[i].getName());
! } catch (LinkageError e) {
! checkException(e, messages[i], exceptions[i]);
! }
! }
! }
!
! static void checkException(Throwable actual, String msg, Class<?> expected) {
! if (!actual.getClass().equals(expected))
! throw new Error("Unexpected exception: got " + actual.getClass().getName()
! + " but expected " + expected.getName());
! if (!actual.getMessage().contains(msg))
! throw new Error("Wrong " + actual.getClass().getSimpleName() +": \"" +
! actual.getMessage() + "\" does not contain \"" +
! msg + "\"");
! System.out.println("OK - got expected exception: " + actual);
}
static void checkHost(Class<?> target, Class<?> expected) {
System.out.println("Checking nest host of " + target.getName());
Class<?> host = target.getNestHost();
--- 174,192 ----
new Class<?>[] { HostWithDuplicateMembers.class,
HostWithDuplicateMembers.Member1.class,
HostWithDuplicateMembers.Member2.class },
true);
! // Hosts with only "bad" members
Class<?>[] bad = {
HostOfMemberNoHost.class,
HostOfMemberMissingHost.class,
HostOfMemberNotOurHost.class,
HostOfMemberNotInstanceHost.class,
HostOfMemberMalformedHost.class,
};
! checkSingletonNests(bad);
}
static void checkHost(Class<?> target, Class<?> expected) {
System.out.println("Checking nest host of " + target.getName());
Class<?> host = target.getNestHost();
< prev index next >