Skip to content

Commit 849bbf0

Browse files
zhuzhuman978sbrannen
authored andcommitted
Simplify if statements and replace try-finally with try-with-resources
Closes gh-23445
1 parent fabdb07 commit 849bbf0

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,19 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
6464

6565
@Override
6666
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
67-
if (NAMESPACES_FEATURE_NAME.equals(name)) {
68-
return this.namespacesFeature;
69-
}
70-
else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
71-
return this.namespacePrefixesFeature;
72-
}
73-
else if (IS_STANDALONE_FEATURE_NAME.equals(name)) {
74-
if (this.isStandalone != null) {
75-
return this.isStandalone;
76-
}
77-
else {
78-
throw new SAXNotSupportedException("startDocument() callback not completed yet");
79-
}
80-
}
81-
else {
82-
return super.getFeature(name);
67+
switch (name) {
68+
case NAMESPACES_FEATURE_NAME:
69+
return this.namespacesFeature;
70+
case NAMESPACE_PREFIXES_FEATURE_NAME:
71+
return this.namespacePrefixesFeature;
72+
case IS_STANDALONE_FEATURE_NAME:
73+
if (this.isStandalone != null) {
74+
return this.isStandalone;
75+
} else {
76+
throw new SAXNotSupportedException("startDocument() callback not completed yet");
77+
}
78+
default:
79+
return super.getFeature(name);
8380
}
8481
}
8582

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,9 @@ protected void prepareTransactionalConnection(Connection con, TransactionDefinit
408408
throws SQLException {
409409

410410
if (isEnforceReadOnly() && definition.isReadOnly()) {
411-
Statement stmt = con.createStatement();
412-
try {
411+
try (Statement stmt = con.createStatement()) {
413412
stmt.executeUpdate("SET TRANSACTION READ ONLY");
414413
}
415-
finally {
416-
stmt.close();
417-
}
418414
}
419415
}
420416

0 commit comments

Comments
 (0)