1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8212703 27 * @summary Test JAVA2D_FONTPATH env. var does not set a system property 28 */ 29 30 import java.io.BufferedReader; 31 import java.io.File; 32 import java.io.InputStreamReader; 33 import java.util.HashMap; 34 import java.util.List; 35 import java.util.Map; 36 37 public class FontPathEnvTest { 38 39 public static void main(String args[]) { 40 String env = System.getenv("JAVA2D_FONTPATH"); 41 if (env == null) { 42 createChild(); 43 } else { 44 String prop = System.getProperty("sun.java2d.fontpath"); 45 if (prop != null && env.equals(prop)) { 46 throw new RuntimeException("sun.java2d.fontpath property set"); 47 } 48 } 49 } 50 51 static void createChild() { 52 String cpDir = System.getProperty("java.class.path"); 53 Map<String, String> env = new HashMap<String, String>(); 54 env.put("JAVA2D_FONTPATH", "anyValue"); 55 String jHome = System.getProperty("java.home"); 56 String jCmd = jHome + File.separator + "bin" + File.separator + "java"; 57 int exitValue = doExec(env, jCmd, "-cp", cpDir, "FontPathEnvTest"); 58 if (exitValue != 0) { 59 throw new RuntimeException("Test Failed"); 60 } 61 } 62 63 static int doExec(Map<String, String> envToSet, String... cmds) { 64 Process p = null; 65 ProcessBuilder pb = new ProcessBuilder(cmds); 66 Map<String, String> env = pb.environment(); 67 for (String cmd : cmds) { 68 System.out.print(cmd + " "); 69 } 70 System.out.println(); 71 if (envToSet != null) { 72 env.putAll(envToSet); 73 } 74 BufferedReader rdr = null; 75 try { 76 pb.redirectErrorStream(true); 77 p = pb.start(); 78 rdr = new BufferedReader(new InputStreamReader(p.getInputStream())); 79 String in = rdr.readLine(); 80 while (in != null) { 81 in = rdr.readLine(); 82 System.out.println(in); 83 } 84 p.waitFor(); 85 p.destroy(); 86 } catch (Exception ex) { 87 ex.printStackTrace(); 88 } 89 return p.exitValue(); 90 } 91 }