changeset 15361:8559f6e0a25d

6469513: (smartcardio) CardPermission(String termName, String actions) violates specification Summary: Changed to allow null actions value Reviewed-by: xuelei
author valeriep
date Fri, 12 Aug 2016 00:10:07 +0000
parents 997eb92cd683
children 5c93d90ca062
files src/java.smartcardio/share/classes/javax/smartcardio/CardPermission.java test/javax/smartcardio/TestCardPermission.java
diffstat 2 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.smartcardio/share/classes/javax/smartcardio/CardPermission.java	Thu Aug 11 23:41:48 2016 +0300
+++ b/src/java.smartcardio/share/classes/javax/smartcardio/CardPermission.java	Fri Aug 12 00:10:07 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -118,7 +118,7 @@
     /**
      * @serial
      */
-    private volatile String actions;
+    private final String actions;
 
     /**
      * Constructs a new CardPermission with the specified actions.
@@ -143,10 +143,14 @@
             throw new NullPointerException();
         }
         mask = getMask(actions);
+        this.actions = getActions(mask);
     }
 
     private static int getMask(String actions) {
-        if ((actions == null) || (actions.length() == 0)) {
+        if (actions == null) {
+            return 0;
+        }
+        if (actions.length() == 0) {
             throw new IllegalArgumentException("actions must not be empty");
         }
 
@@ -177,6 +181,9 @@
     }
 
     private static String getActions(int mask) {
+        if (mask == 0) {
+            return null;
+        }
         if (mask == A_ALL) {
             return S_ALL;
         }
@@ -200,9 +207,6 @@
      * @return the canonical string representation of the actions.
      */
     public String getActions() {
-        if (actions == null) {
-            actions = getActions(mask);
-        }
         return actions;
     }
 
@@ -278,10 +282,6 @@
 
     private void writeObject(ObjectOutputStream s) throws IOException {
         // Write out the actions. The superclass takes care of the name.
-        // Call getActions to make sure actions field is initialized
-        if (actions == null) {
-            getActions();
-        }
         s.defaultWriteObject();
     }
 
@@ -291,5 +291,4 @@
         s.defaultReadObject();
         mask = getMask(actions);
     }
-
 }
--- a/test/javax/smartcardio/TestCardPermission.java	Thu Aug 11 23:41:48 2016 +0300
+++ b/test/javax/smartcardio/TestCardPermission.java	Fri Aug 12 00:10:07 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 6293767
+ * @bug 6293767 6469513
  * @summary Test for the CardPermission class
  * @author Andreas Sterbenz
  * @compile --add-modules=java.smartcardio TestCardPermission.java
@@ -49,15 +49,14 @@
         test("Reset,coNnect", "connect,reset");
         test("exclusive,*,connect", "*");
         test("connect,reset,exclusive,transmitControl,getBasicChannel,openLogicalChannel", "*");
+        test(null, null);
 
-        invalid(null);
         invalid("");
         invalid("foo");
         invalid("connect, reset");
         invalid("connect,,reset");
         invalid("connect,");
         invalid(",connect");
-        invalid("");
     }
 
     private static void invalid(String s) throws Exception {
@@ -77,7 +76,7 @@
         CardPermission p = new CardPermission("*", actions);
         System.out.println(p);
         String a = p.getActions();
-        if (canon.equals(a) == false) {
+        if (canon != null && canon.equals(a) == false) {
             throw new Exception("Canonical actions mismatch: " + canon + " != " + a);
         }
     }