Skip to content

Commit 78dad4c

Browse files
committed
Jdbc4SqlXmlHandler returns null as documented (instead of throwing NPE)
Issue: SPR-13782
1 parent 7f7f249 commit 78dad4c

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,43 +53,55 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler {
5353

5454
@Override
5555
public String getXmlAsString(ResultSet rs, String columnName) throws SQLException {
56-
return rs.getSQLXML(columnName).getString();
56+
SQLXML xmlObject = rs.getSQLXML(columnName);
57+
return (xmlObject != null ? xmlObject.getString() : null);
5758
}
5859

5960
@Override
6061
public String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException {
61-
return rs.getSQLXML(columnIndex).getString();
62+
SQLXML xmlObject = rs.getSQLXML(columnIndex);
63+
return (xmlObject != null ? xmlObject.getString() : null);
6264
}
6365

6466
@Override
6567
public InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException {
66-
return rs.getSQLXML(columnName).getBinaryStream();
68+
SQLXML xmlObject = rs.getSQLXML(columnName);
69+
return (xmlObject != null ? xmlObject.getBinaryStream() : null);
6770
}
6871

6972
@Override
7073
public InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
71-
return rs.getSQLXML(columnIndex).getBinaryStream();
74+
SQLXML xmlObject = rs.getSQLXML(columnIndex);
75+
return (xmlObject != null ? xmlObject.getBinaryStream() : null);
7276
}
7377

7478
@Override
7579
public Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException {
76-
return rs.getSQLXML(columnName).getCharacterStream();
80+
SQLXML xmlObject = rs.getSQLXML(columnName);
81+
return (xmlObject != null ? xmlObject.getCharacterStream() : null);
7782
}
7883

7984
@Override
8085
public Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
81-
return rs.getSQLXML(columnIndex).getCharacterStream();
86+
SQLXML xmlObject = rs.getSQLXML(columnIndex);
87+
return (xmlObject != null ? xmlObject.getCharacterStream() : null);
8288
}
8389

8490
@Override
8591
public Source getXmlAsSource(ResultSet rs, String columnName, Class<? extends Source> sourceClass) throws SQLException {
8692
SQLXML xmlObject = rs.getSQLXML(columnName);
93+
if (xmlObject == null) {
94+
return null;
95+
}
8796
return (sourceClass != null ? xmlObject.getSource(sourceClass) : xmlObject.getSource(DOMSource.class));
8897
}
8998

9099
@Override
91100
public Source getXmlAsSource(ResultSet rs, int columnIndex, Class<? extends Source> sourceClass) throws SQLException {
92101
SQLXML xmlObject = rs.getSQLXML(columnIndex);
102+
if (xmlObject == null) {
103+
return null;
104+
}
93105
return (sourceClass != null ? xmlObject.getSource(sourceClass) : xmlObject.getSource(DOMSource.class));
94106
}
95107

spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,7 +112,7 @@ public interface SqlXmlHandler {
112112
* database and driver.
113113
* @param rs the ResultSet to retrieve the content from
114114
* @param columnName the column name to use
115-
* @return the content as character stream
115+
* @return the content as character stream, or {@code null} in case of SQL NULL
116116
* @throws SQLException if thrown by JDBC methods
117117
* @see java.sql.ResultSet#getSQLXML
118118
* @see java.sql.SQLXML#getCharacterStream
@@ -126,7 +126,7 @@ public interface SqlXmlHandler {
126126
* database and driver.
127127
* @param rs the ResultSet to retrieve the content from
128128
* @param columnIndex the column index to use
129-
* @return the content as character stream
129+
* @return the content as character stream, or {@code null} in case of SQL NULL
130130
* @throws SQLException if thrown by JDBC methods
131131
* @see java.sql.ResultSet#getSQLXML
132132
* @see java.sql.SQLXML#getCharacterStream
@@ -141,7 +141,7 @@ public interface SqlXmlHandler {
141141
* @param rs the ResultSet to retrieve the content from
142142
* @param columnName the column name to use
143143
* @param sourceClass the implementation class to be used
144-
* @return the content as character stream
144+
* @return the content as character stream, or {@code null} in case of SQL NULL
145145
* @throws SQLException if thrown by JDBC methods
146146
* @see java.sql.ResultSet#getSQLXML
147147
* @see java.sql.SQLXML#getSource
@@ -156,7 +156,7 @@ public interface SqlXmlHandler {
156156
* @param rs the ResultSet to retrieve the content from
157157
* @param columnIndex the column index to use
158158
* @param sourceClass the implementation class to be used
159-
* @return the content as character stream
159+
* @return the content as character stream, or {@code null} in case of SQL NULL
160160
* @throws SQLException if thrown by JDBC methods
161161
* @see java.sql.ResultSet#getSQLXML
162162
* @see java.sql.SQLXML#getSource

0 commit comments

Comments
 (0)