jdk/src/share/classes/sun/security/util/DerValue.java
changeset 2065 d0bafa066816
parent 2 90ce3da70b43
child 4188 f67abce80f05
--- a/jdk/src/share/classes/sun/security/util/DerValue.java	Mon Feb 23 10:04:25 2009 +0800
+++ b/jdk/src/share/classes/sun/security/util/DerValue.java	Mon Feb 23 10:04:52 2009 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2009 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
@@ -65,7 +65,7 @@
     protected DerInputBuffer    buffer;
 
     /**
-     * The DER-encoded data of the value.
+     * The DER-encoded data of the value, never null
      */
     public final DerInputStream data;
 
@@ -378,8 +378,6 @@
                         ("Indefinite length encoding not supported");
             length = DerInputStream.getLength(in);
         }
-        if (length == 0)
-            return null;
 
         if (fullyBuffered && in.available() != length)
             throw new IOException("extra data given to DerValue constructor");
@@ -477,6 +475,11 @@
                 "DerValue.getOctetString, not an Octet String: " + tag);
         }
         bytes = new byte[length];
+        // Note: do not tempt to call buffer.read(bytes) at all. There's a
+        // known bug that it returns -1 instead of 0.
+        if (length == 0) {
+            return bytes;
+        }
         if (buffer.read(bytes) != length)
             throw new IOException("short read on DerValue buffer");
         if (isConstructed()) {