Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javah/T4942232/MissingParamClassTest.java
38813 views
/*1* Copyright (c) 2013, 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 494223226* @summary Verifies that javah won't attempt to generate a header file if a27* native method in a supplied class contains a parameter type whose corresponding28* class is missing or not in the classpath29* @library /tools/javac/lib30* @build ToolBox31* @run compile MissingParamClassTest.java32* @clean MissingParamClassException33* @run main MissingParamClassTest34* @run compile MissingParamClassTest.java35* @clean Param36* @run main MissingParamClassTest37*/3839import java.nio.file.Files;40import java.nio.file.Paths;41import java.util.ArrayList;42import java.util.List;4344//original test: test/tools/javah/MissingParamClassTest.sh45public class MissingParamClassTest {4647public static void main(String[] args) throws Exception {48//first steps done now by jtreg49//"${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d . "${TESTSRC}${FS}ParamClassTest.java" "${TESTSRC}${FS}MissingParamClassException.java"50//rm -f MissingParamClassException.class5152//"${TESTJAVA}${FS}bin${FS}javah" ${TESTTOOLVMOPTS} ParamClassTest 2>${TMP1}53List<String> errOutput = new ArrayList<>();54ToolBox.JavaToolArgs javahParams =55new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)56.setAllArgs("-classpath", System.getProperty("test.classes"), "ParamClassTest")57.setErrOutput(errOutput);58ToolBox.javah(javahParams);5960//if [ -f $GENERATED_HEADER_FILE ]; then fail61//if [ ! -s ${TMP1} ]; then fail62if (Files.exists(Paths.get("ParamClassTest.h")) || errOutput.size() == 0)63throw new AssertionError("The only output generated by javah must be an error message");64//jtreg again65//rm -f MissingParamClassException.class ParamClassTest.class66//rm -f $GENERATED_HEADER_FILE $TMP167}6869}7071class MissingParamClassException extends Exception {72public MissingParamClassException() {73System.out.println("MissingParamClassException constructor called");74}75}7677class ParamClassTest {78public native void method(Param s);7980public static void main(String args[]) {81}82}8384class Param extends MissingParamClassException {85Param() {86System.out.println("Param constructor");87}88}899091