Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/instrument/NullRedefineClassesTests.java
38813 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 4920005 488279826* @summary make sure redefineClasses throws NullPointerException in the right places.27* @author Robert Field as modified from the code of Gabriel Adauto, Wily Technology28*29* @run build NullRedefineClassesTests30* @run shell MakeJAR.sh redefineAgent31* @run main/othervm -javaagent:redefineAgent.jar NullRedefineClassesTests NullRedefineClassesTests32*/3334import java.lang.instrument.ClassDefinition;35import java.lang.instrument.UnmodifiableClassException;3637public class38NullRedefineClassesTests39extends ASimpleInstrumentationTestCase40{4142/**43* Constructor for NullRedefineClassesTests.44* @param name45*/46public NullRedefineClassesTests(String name) {47super(name);48}4950public static void51main (String[] args) throws Throwable {52ATestCaseScaffold test = new NullRedefineClassesTests(args[0]);53test.runTest();54}5556protected final void57doRunTest() throws ClassNotFoundException, UnmodifiableClassException {58testNullRedefineClasses();59}606162public void63testNullRedefineClasses() throws ClassNotFoundException, UnmodifiableClassException {64boolean caught;6566// Test that a null argument throws NullPointerException67caught = false;68try {69fInst.redefineClasses(null);70} catch (NullPointerException npe) {71caught = true;72}73assertTrue(caught);7475// Test that a null element throws NullPointerException76caught = false;77try {78fInst.redefineClasses(new ClassDefinition[]{ null });79} catch (NullPointerException npe) {80caught = true;81}82assertTrue(caught);8384// Test that a null element amonst others throws NullPointerException85caught = false;86ClassDefinition cd = new ClassDefinition(DummyClass.class, new byte[] {1, 2, 3});87try {88fInst.redefineClasses(new ClassDefinition[]{ cd, null });89} catch (NullPointerException npe) {90caught = true;91}92assertTrue(caught);9394// Test that a null class throws NullPointerException95caught = false;96try {97new ClassDefinition(null, new byte[] {1, 2, 3});98} catch (NullPointerException npe) {99caught = true;100}101assertTrue(caught);102103// Test that a null byte array throws NullPointerException104caught = false;105try {106new ClassDefinition(DummyClass.class, null);107} catch (NullPointerException npe) {108caught = true;109}110assertTrue(caught);111}112}113114115