8130264: change the mechanism by which JDK loads the platform-specific PrinterJob implementation
authorprr
Fri, 30 Nov 2018 10:55:59 -0800
changeset 52836 98792298b309
parent 52835 40281bb2feb6
child 52837 84cc04e403ab
8130264: change the mechanism by which JDK loads the platform-specific PrinterJob implementation Reviewed-by: serb, rriggs
src/java.base/share/native/libjava/System.c
src/java.base/share/native/libjava/java_props.h
src/java.base/unix/native/libjava/java_props_md.c
src/java.base/windows/native/libjava/java_props_md.c
src/java.desktop/macosx/classes/sun/print/PlatformPrinterJobProxy.java
src/java.desktop/share/classes/java/awt/print/PrinterJob.java
src/java.desktop/share/classes/sun/print/PlatformPrinterJobProxy.java
src/java.desktop/windows/classes/sun/print/PlatformPrinterJobProxy.java
test/jdk/java/awt/print/PrinterJob/CheckPrinterJobSystemProperty.java
--- a/src/java.base/share/native/libjava/System.c	Fri Nov 30 17:14:48 2018 +0530
+++ b/src/java.base/share/native/libjava/System.c	Fri Nov 30 10:55:59 2018 -0800
@@ -206,19 +206,6 @@
     /* patch level */
     PUTPROP(propArray, _sun_os_patch_level_NDX, sprops->patch_level);
 
-    /* Printing properties */
-    /* Note: java.awt.printerjob is an implementation private property which
-     * just happens to have a java.* name because it is referenced in
-     * a java.awt class. It is the mechanism by which the implementation
-     * finds the appropriate class in the JRE for the platform.
-     * It is explicitly not designed to be overridden by clients as
-     * a way of replacing the implementation class, and in any case
-     * the mechanism by which the class is loaded is constrained to only
-     * find and load classes that are part of the JRE.
-     * This property may be removed if that mechanism is redesigned
-     */
-    PUTPROP(propArray, _java_awt_printerjob_NDX, sprops->printerJob);
-
     PUTPROP(propArray, _awt_toolkit_NDX, sprops->awt_toolkit);
 
     /* Java2D properties */
--- a/src/java.base/share/native/libjava/java_props.h	Fri Nov 30 17:14:48 2018 +0530
+++ b/src/java.base/share/native/libjava/java_props.h	Fri Nov 30 10:55:59 2018 -0800
@@ -69,7 +69,6 @@
     char *sun_stdout_encoding;
     char *sun_stderr_encoding;
 
-    char *printerJob;
     char *graphics_env;
     char *awt_toolkit;
 
--- a/src/java.base/unix/native/libjava/java_props_md.c	Fri Nov 30 17:14:48 2018 +0530
+++ b/src/java.base/unix/native/libjava/java_props_md.c	Fri Nov 30 10:55:59 2018 -0800
@@ -391,13 +391,6 @@
     }
 #endif /* MACOSX */
 
-    /* Printing properties */
-#ifdef MACOSX
-    sprops.printerJob = "sun.lwawt.macosx.CPrinterJob";
-#else
-    sprops.printerJob = "sun.print.PSPrinterJob";
-#endif
-
     /* patches/service packs installed */
     sprops.patch_level = NULL;      // leave it undefined
 
--- a/src/java.base/windows/native/libjava/java_props_md.c	Fri Nov 30 17:14:48 2018 +0530
+++ b/src/java.base/windows/native/libjava/java_props_md.c	Fri Nov 30 10:55:59 2018 -0800
@@ -376,9 +376,6 @@
         sprops.tmp_dir = _wcsdup(tmpdir);
     }
 
-    /* Printing properties */
-    sprops.printerJob = "sun.awt.windows.WPrinterJob";
-
     /* Java2D properties */
     sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment";
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.desktop/macosx/classes/sun/print/PlatformPrinterJobProxy.java	Fri Nov 30 10:55:59 2018 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.print;
+
+import java.awt.print.PrinterJob;
+
+public class PlatformPrinterJobProxy {
+
+   public static PrinterJob getPrinterJob() {
+       return new sun.lwawt.macosx.CPrinterJob();
+   }
+}
+
+
--- a/src/java.desktop/share/classes/java/awt/print/PrinterJob.java	Fri Nov 30 17:14:48 2018 +0530
+++ b/src/java.desktop/share/classes/java/awt/print/PrinterJob.java	Fri Nov 30 10:55:59 2018 -0800
@@ -72,20 +72,7 @@
         if (security != null) {
             security.checkPrintJobAccess();
         }
-        return java.security.AccessController.doPrivileged(
-            new java.security.PrivilegedAction<PrinterJob>() {
-            public PrinterJob run() {
-                String nm = System.getProperty("java.awt.printerjob", null);
-                try {
-                    return (PrinterJob)Class.forName(nm).
-                                             getConstructor().newInstance();
-                } catch (ClassNotFoundException e) {
-                    throw new AWTError("PrinterJob not found: " + nm);
-                } catch (ReflectiveOperationException e) {
-                 throw new AWTError("Could not instantiate PrinterJob: " + nm);
-                }
-            }
-        });
+        return sun.print.PlatformPrinterJobProxy.getPrinterJob();
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.desktop/share/classes/sun/print/PlatformPrinterJobProxy.java	Fri Nov 30 10:55:59 2018 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.print;
+
+import java.awt.print.PrinterJob;
+
+public class PlatformPrinterJobProxy {
+
+   public static PrinterJob getPrinterJob() {
+       return new sun.print.PSPrinterJob();
+   }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.desktop/windows/classes/sun/print/PlatformPrinterJobProxy.java	Fri Nov 30 10:55:59 2018 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.print;
+
+import java.awt.print.PrinterJob;
+
+public class PlatformPrinterJobProxy {
+
+   public static PrinterJob getPrinterJob() {
+       return new sun.awt.windows.WPrinterJob();
+   }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/awt/print/PrinterJob/CheckPrinterJobSystemProperty.java	Fri Nov 30 10:55:59 2018 -0800
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @run CheckPrinterJobSystemProperty
+ * @bug 8130264
+ * @summary verify the PrinterJob implementation class name is not
+ *          polluting system properties
+ */
+
+public class CheckPrinterJobSystemProperty {
+
+     public static void main(String[] args) {
+         String pjProp = System.getProperty("java.awt.printerjob");
+         if (pjProp != null) {
+             throw new RuntimeException("pjProp = " + pjProp);
+         }
+     }
+}