changeset 2110:558f2a424bfa

6919610: KeyTabInputStream uses static field for per-instance value Reviewed-by: mullan
author weijun
date Tue, 26 Jan 2010 17:03:48 +0800
parents e67bf9abc6a5
children f544825d0976
files src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java test/sun/security/krb5/ktab/KeyTabIndex.java
diffstat 2 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java	Mon Jan 25 15:41:37 2010 +0000
+++ b/src/share/classes/sun/security/krb5/internal/ktab/KeyTabInputStream.java	Tue Jan 26 17:03:48 2010 +0800
@@ -1,5 +1,5 @@
 /*
- * Portions Copyright 2000-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * Portions Copyright 2000-2010 Sun Microsystems, Inc.  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
@@ -49,7 +49,7 @@
 public class KeyTabInputStream extends KrbDataInputStream implements KeyTabConstants {
 
     boolean DEBUG = Krb5.DEBUG;
-    static int index;
+    int index;
 
     public KeyTabInputStream(InputStream is) {
         super(is);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/security/krb5/ktab/KeyTabIndex.java	Tue Jan 26 17:03:48 2010 +0800
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @bug 6919610
+ * @summary KeyTabInputStream uses static field for per-instance value
+ */
+import sun.security.krb5.PrincipalName;
+import sun.security.krb5.internal.ktab.KeyTab;
+
+public class KeyTabIndex {
+    public static void main(String[] args) throws Exception {
+        KeyTab kt = KeyTab.create("ktab");
+        // Two entries with very different length, so that it's easy to
+        // observice the abnormal change of "index" field.
+        kt.addEntry(new PrincipalName(
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@A"),
+                "x".toCharArray(), 1);
+        kt.addEntry(new PrincipalName("a@A"), "x".toCharArray(), 1);
+        kt.save();
+        Runnable t = new Runnable() {
+            @Override
+            public void run() {
+                KeyTab.getInstance("ktab").getClass();
+            }
+        };
+        KeyTab.refresh();
+        for (int i=0; i<10; i++) {
+            new Thread(t).start();
+        }
+    }
+}