changeset 10883:bc09cce3617a

8196617: FX print tests fail with NPE in some environments Summary: fix NPE in J2DPrinter.getMediaName() Reviewed-by: kcr, prr
author lbourges
date Fri, 23 Mar 2018 21:37:07 +0100
parents 3bc097d85c79
children 018c75e3aad8
files modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java
diffstat 1 files changed, 6 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java	Fri Mar 23 15:06:54 2018 +0530
+++ b/modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinter.java	Fri Mar 23 21:37:07 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -40,7 +40,6 @@
 import javax.print.attribute.standard.Chromaticity;
 import javax.print.attribute.standard.Copies;
 import javax.print.attribute.standard.CopiesSupported;
-import javax.print.attribute.standard.Destination;
 import javax.print.attribute.standard.Media;
 import javax.print.attribute.standard.MediaPrintableArea;
 import javax.print.attribute.standard.MediaSize;
@@ -61,8 +60,6 @@
 import javafx.print.Printer;
 import javafx.print.Printer.MarginType;
 import javafx.print.Collation;
-import javafx.print.Paper;
-import javafx.print.PaperSource;
 import javafx.print.PageRange;
 import javafx.print.PrintColor;
 import javafx.print.PageOrientation;
@@ -791,15 +788,12 @@
      * to pre-defined javafx.print Papers. For all other reported media we
      * create a printer-specific instance and store it in a per-printer map.
      */
-    private Map<MediaSizeName, Paper> mediaToPaperMap;
-    private Map<Paper, MediaSizeName> paperToMediaMap;
+    private final Map<MediaSizeName, Paper> mediaToPaperMap
+         = new HashMap<MediaSizeName, Paper>();
+    private final Map<Paper, MediaSizeName> paperToMediaMap
+         = new HashMap<Paper, MediaSizeName>();
+
     private synchronized final Paper addPaper(MediaSizeName media) {
-
-        if (mediaToPaperMap == null) {
-            mediaToPaperMap = new HashMap<MediaSizeName, Paper>();
-            paperToMediaMap = new HashMap<Paper, MediaSizeName>();
-        }
-
         Paper paper = predefinedPaperMap.get(media);
         if (paper == null ) {
             MediaSize sz = MediaSize.getMediaSizeForName(media);