Path: blob/master/test/hotspot/jtreg/runtime/LoadLibrary/TestSunBootLibraryPath.java
40942 views
/*1* Copyright (c) 2019, 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* @test TestSunBootLibraryPath.java25* @bug 822702126* @summary Confirm using too-long paths in sun.boot.library.path causes failure and useful error message.27* @author afarley28* @library /test/lib29* @build jdk.test.lib.process.ProcessTools30* @run driver TestSunBootLibraryPath31*/3233import jdk.test.lib.process.ProcessTools;3435public class TestSunBootLibraryPath {36static String expectedErrorMessage = "The VM tried to use a path that exceeds the maximum path length for this system.";3738public static void main(String[] args) throws Exception {39// Allows us to re-use this class as a do-nothing test class simply by passing a "Do-Nothing" argument.40if (args.length == 0) {41// Grab any path.42String tooLongPath = System.getProperty("sun.boot.library.path");43// Add enough characters to make it "too long".44tooLongPath += "a".repeat(5000);45// Start a java process with this property set, and check that:46// 1) The process failed and47// 2) The error message was correct.48ProcessTools.executeTestJvm("-Dsun.boot.library.path=" + tooLongPath,49"TestSunBootLibraryPath",50"'Do-Nothing'")51.shouldNotHaveExitValue(0)52.stdoutShouldContain(expectedErrorMessage);53} else if (!args[0].equals("Do-Nothing")) {54// Fail, to prevent accidental args from causing accidental test passing.55throw new IllegalArgumentException("Test was launched with an invalid argument.");56}57}58}596061