changeset 4974:b518b160607f

7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl Reviewed-by: forax
author lancea
date Thu, 26 Jan 2012 19:41:35 -0500
parents 350971f50949
children 5ee30ab905db
files src/share/classes/com/sun/rowset/CachedRowSetImpl.java src/share/classes/com/sun/rowset/internal/BaseRow.java src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java src/share/classes/javax/sql/rowset/serial/SerialStruct.java
diffstat 5 files changed, 42 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java	Thu Jan 26 09:51:35 2012 +0100
+++ b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java	Thu Jan 26 19:41:35 2012 -0500
@@ -6431,7 +6431,8 @@
      * @see #setKeyColumns
      */
     public int[] getKeyColumns() throws SQLException {
-        return keyCols;
+        int[]keyColumns  = this.keyCols;
+        return (keyColumns == null) ? null : Arrays.copyOf(keyColumns, keyColumns.length);
     }
 
 
--- a/src/share/classes/com/sun/rowset/internal/BaseRow.java	Thu Jan 26 09:51:35 2012 +0100
+++ b/src/share/classes/com/sun/rowset/internal/BaseRow.java	Thu Jan 26 19:41:35 2012 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -27,6 +27,7 @@
 
 import java.sql.*;
 import java.io.*;
+import java.util.Arrays;
 
 /**
  * The abstract base class from which the classes <code>Row</code>
@@ -65,7 +66,8 @@
  * original values
  */
     public Object[] getOrigRow() {
-        return origVals;
+        Object[] origRow = this.origVals;
+        return (origRow == null) ? null: Arrays.copyOf(origRow, origRow.length);
     }
 
 /**
--- a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Thu Jan 26 09:51:35 2012 +0100
+++ b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java	Thu Jan 26 19:41:35 2012 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -25,6 +25,7 @@
 package javax.sql.rowset.serial;
 
 import java.sql.*;
+import java.util.Arrays;
 import java.util.Map;
 
 /**
@@ -119,7 +120,7 @@
             "object with null parameters");
         }
         // assign our local reference to the attribute stream
-        attrib = attributes;
+        attrib = Arrays.copyOf(attributes, attributes.length);
         // init the index point before the head of the stream
         idx = -1;
         // set the map
--- a/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java	Thu Jan 26 09:51:35 2012 +0100
+++ b/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java	Thu Jan 26 19:41:35 2012 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -25,11 +25,10 @@
 
 package javax.sql.rowset.serial;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.sql.*;
-import javax.sql.*;
-import java.io.*;
-import java.lang.String;
-import java.math.*;
 import java.util.Map;
 import java.util.Vector;
 
@@ -444,16 +443,15 @@
          * will need to track if a field is SQL null for itself
          */
         if (x == null) {
-            attribs.add(x);
-            return;
+            attribs.add(null);
+        } else {
+            /*
+             * We have to write out a SerialStruct that contains
+             * the name of this class otherwise we don't know
+             * what to re-instantiate during readSQL()
+             */
+            attribs.add(new SerialStruct(x, map));
         }
-
-        /*
-         * We have to write out a SerialStruct that contains
-         * the name of this class otherwise we don't know
-         * what to re-instantiate during readSQL()
-         */
-        attribs.add(new SerialStruct(x, map));
     }
 
     /**
@@ -470,10 +468,10 @@
     @SuppressWarnings("unchecked")
     public void writeRef(Ref x) throws SQLException {
         if (x == null) {
-            attribs.add(x);
-            return;
+            attribs.add(null);
+        } else {
+            attribs.add(new SerialRef(x));
         }
-        attribs.add(new SerialRef(x));
     }
 
     /**
@@ -490,10 +488,10 @@
     @SuppressWarnings("unchecked")
     public void writeBlob(Blob x) throws SQLException {
         if (x == null) {
-            attribs.add(x);
-            return;
+            attribs.add(null);
+        } else {
+            attribs.add(new SerialBlob(x));
         }
-        attribs.add(new SerialBlob(x));
     }
 
     /**
@@ -510,10 +508,10 @@
     @SuppressWarnings("unchecked")
     public void writeClob(Clob x) throws SQLException {
         if (x == null) {
-            attribs.add(x);
-            return;
+            attribs.add(null);
+        } else {
+            attribs.add(new SerialClob(x));
         }
-        attribs.add(new SerialClob(x));
     }
 
     /**
@@ -554,10 +552,10 @@
     @SuppressWarnings("unchecked")
     public void writeArray(Array x) throws SQLException {
         if (x == null) {
-            attribs.add(x);
-            return;
+            attribs.add(null);
+        } else {
+            attribs.add(new SerialArray(x, map));
         }
-        attribs.add(new SerialArray(x, map));
     }
 
     /**
@@ -574,11 +572,10 @@
     @SuppressWarnings("unchecked")
     public void writeURL(java.net.URL url) throws SQLException {
         if (url == null) {
-            attribs.add(url);
-            return;
+            attribs.add(null);
+        } else {
+            attribs.add(new SerialDatalink(url));
         }
-        attribs.add(new SerialDatalink(url));
-
     }
 
 
--- a/src/share/classes/javax/sql/rowset/serial/SerialStruct.java	Thu Jan 26 09:51:35 2012 +0100
+++ b/src/share/classes/javax/sql/rowset/serial/SerialStruct.java	Thu Jan 26 19:41:35 2012 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, 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
@@ -29,6 +29,7 @@
 import javax.sql.*;
 import java.io.*;
 import java.math.*;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Vector;
 
@@ -174,7 +175,8 @@
      * @throws SerialException if an error occurs
      */
     public Object[]  getAttributes() throws SerialException {
-        return attribs;
+        Object[] val = this.attribs;
+        return (val == null) ? null : Arrays.copyOf(val, val.length);
     }
 
     /**
@@ -197,7 +199,8 @@
     public Object[] getAttributes(Map<String,Class<?>> map)
         throws SerialException
     {
-       return attribs;
+        Object[] val = this.attribs;
+        return (val == null) ? null : Arrays.copyOf(val, val.length);
     }