Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/Class/forName/NonJavaNames.sh
38828 views
#1# Copyright (c) 2003, 2012, 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# @test24# @bug 495255825# @summary Verify names that aren't legal Java names are accepted by forName.26# @author Joseph D. Darcy27# @compile -source 1.5 -target 1.5 NonJavaNames.java28# @run shell NonJavaNames.sh2930# This test uses hand-generated class files stored in the ./classes31# directory. After the renaming done below, those class files have32# single character names that are legal class names under class file33# version 49 but *not* legal Java language identifiers; e.g. "3" and34# "+". First, Z.java is compiled to Z.class using "-target 1.5."35# Next, to create a test class file, the appropriate name structures36# within the class files are updated, as is the "Hello world" string37# the class's main method prints out. If the definition of the38# semantics of "-target 1.5" changes, the test class files should be39# regenerated.4041# Verify directory context variables are set42if [ "${TESTJAVA}" = "" ]43then44echo "TESTJAVA not set. Test cannot execute. Failed."45exit 146fi4748if [ "${TESTSRC}" = "" ]49then50echo "TESTSRC not set. Test cannot execute. Failed."51exit 152fi5354if [ "${TESTCLASSES}" = "" ]55then56echo "TESTCLASSES not set. Test cannot execute. Failed."57exit 158fi5960# All preconditions are met; run the tests6162OS=`uname -s`;63# Set classpath separator64case "$OS" in65Windows* | CYGWIN* )66SEP=";"67;;6869* )70SEP=":"71esac7273# Copy "hyphen.class" to "-.class"7475COPYHYPHEN="cp ${TESTSRC}/classes/hyphen.class ${TESTCLASSES}/-.class"76$COPYHYPHEN7778COPYCOMMA="cp ${TESTSRC}/classes/comma.class ${TESTCLASSES}/,.class"79$COPYCOMMA8081COPYPERIOD="cp ${TESTSRC}/classes/period.class ${TESTCLASSES}/..class"82$COPYPERIOD8384COPYLEFTSQUARE="cp ${TESTSRC}/classes/left-square.class ${TESTCLASSES}/[.class"85$COPYLEFTSQUARE8687COPYRIGHTSQUARE="cp ${TESTSRC}/classes/right-square.class ${TESTCLASSES}/].class"88$COPYRIGHTSQUARE8990COPYPLUS="cp ${TESTSRC}/classes/plus.class ${TESTCLASSES}/+.class"91$COPYPLUS9293COPYSEMICOLON="cp ${TESTSRC}/classes/semicolon.class ${TESTCLASSES}/;.class"94$COPYSEMICOLON9596JAVA="$TESTJAVA/bin/java ${TESTVMOPTS} -classpath ${TESTSRC}/classes${SEP}${TESTCLASSES}"9798$JAVA NonJavaNames99RESULT=$?100101case "$RESULT" in1020 )103exit 0;104;;105106* )107exit 1108esac109110111112