From 027937e109a74dc5c2bcf0f9acfd6c27fee53a71 Mon Sep 17 00:00:00 2001 From: lancea Date: Thu, 26 Jan 2012 19:41:35 -0500 Subject: [PATCH] 7133815: address the findbug errors in CachedRowSetImpl, SerialStruct, BaseRow, SerialInputImpl, SerialOutputImpl Reviewed-by: forax --- .../com/sun/rowset/CachedRowSetImpl.java | 3 +- .../com/sun/rowset/internal/BaseRow.java | 6 +- .../javax/sql/rowset/serial/SQLInputImpl.java | 5 +- .../sql/rowset/serial/SQLOutputImpl.java | 57 +++++++++---------- .../javax/sql/rowset/serial/SerialStruct.java | 9 ++- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java index 9b4670556..6987537f2 100644 --- a/src/share/classes/com/sun/rowset/CachedRowSetImpl.java +++ b/src/share/classes/com/sun/rowset/CachedRowSetImpl.java @@ -6431,7 +6431,8 @@ public class CachedRowSetImpl extends BaseRowSet implements RowSet, RowSetIntern * @see #setKeyColumns */ public int[] getKeyColumns() throws SQLException { - return keyCols; + int[]keyColumns = this.keyCols; + return (keyColumns == null) ? null : Arrays.copyOf(keyColumns, keyColumns.length); } diff --git a/src/share/classes/com/sun/rowset/internal/BaseRow.java b/src/share/classes/com/sun/rowset/internal/BaseRow.java index 49fce7090..814e7456f 100644 --- a/src/share/classes/com/sun/rowset/internal/BaseRow.java +++ b/src/share/classes/com/sun/rowset/internal/BaseRow.java @@ -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 @@ package com.sun.rowset.internal; import java.sql.*; import java.io.*; +import java.util.Arrays; /** * The abstract base class from which the classes Row @@ -65,7 +66,8 @@ public abstract class BaseRow implements Serializable, Cloneable { * original values */ public Object[] getOrigRow() { - return origVals; + Object[] origRow = this.origVals; + return (origRow == null) ? null: Arrays.copyOf(origRow, origRow.length); } /** diff --git a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java index c4b1e4d91..f05be51c1 100644 --- a/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java +++ b/src/share/classes/javax/sql/rowset/serial/SQLInputImpl.java @@ -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 @@ public class SQLInputImpl implements SQLInput { "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 diff --git a/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java b/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java index 2217e4e2c..b46a880bd 100644 --- a/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java +++ b/src/share/classes/javax/sql/rowset/serial/SQLOutputImpl.java @@ -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 @@ public class SQLOutputImpl implements SQLOutput { * 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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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 @@ public class SQLOutputImpl implements SQLOutput { @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)); - } diff --git a/src/share/classes/javax/sql/rowset/serial/SerialStruct.java b/src/share/classes/javax/sql/rowset/serial/SerialStruct.java index a9462eb86..74d54bbed 100644 --- a/src/share/classes/javax/sql/rowset/serial/SerialStruct.java +++ b/src/share/classes/javax/sql/rowset/serial/SerialStruct.java @@ -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 java.sql.*; 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 @@ public class SerialStruct implements Struct, Serializable, Cloneable { * @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 class SerialStruct implements Struct, Serializable, Cloneable { public Object[] getAttributes(Map> map) throws SerialException { - return attribs; + Object[] val = this.attribs; + return (val == null) ? null : Arrays.copyOf(val, val.length); } -- GitLab