Skip to content

Commit 34efee8

Browse files
committed
Fix 1 warning by lgtm.com wrt not closing resource
1 parent 39c0338 commit 34efee8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/java/org/codehaus/stax2/validation/XMLValidationSchemaFactory.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public static XMLValidationSchemaFactory newInstance(String schemaType)
120120
public static XMLValidationSchemaFactory newInstance(String schemaType, ClassLoader classLoader)
121121
throws FactoryConfigurationError
122122
{
123-
/* First, let's check and map schema type to the shorter internal
124-
* id:
125-
*/
123+
// Let's check and map schema type to the shorter internal id:
126124
String internalId = (String) sSchemaIds.get(schemaType);
127125
if (internalId == null) {
128126
throw new FactoryConfigurationError("Unrecognized schema type (id '"+schemaType+"')");
@@ -131,9 +129,7 @@ public static XMLValidationSchemaFactory newInstance(String schemaType, ClassLoa
131129
String propertyId = SYSTEM_PROPERTY_FOR_IMPL + internalId;
132130
SecurityException secEx = null;
133131

134-
/* First, let's see if there's a system property (overrides other
135-
* settings)
136-
*/
132+
// First, let's see if there's a system property (overrides other settings)
137133
try {
138134
String clsName = System.getProperty(propertyId);
139135
if (clsName != null && clsName.length() > 0) {
@@ -156,9 +152,18 @@ public static XMLValidationSchemaFactory newInstance(String schemaType, ClassLoa
156152
f = new File(f, "lib");
157153
f = new File(f, JAXP_PROP_FILENAME);
158154
if (f.exists()) {
155+
Properties props = new Properties();
159156
try {
160-
Properties props = new Properties();
161-
props.load(new FileInputStream(f));
157+
FileInputStream in = new FileInputStream(f);
158+
// TODO: 15-Jan-2020, tatu -- when upgrading baseline to Java 7+,
159+
// use try-with-resource instead
160+
try {
161+
props.load(in);
162+
} finally {
163+
try {
164+
in.close();
165+
} catch (IOException e) { }
166+
}
162167
String clsName = props.getProperty(propertyId);
163168
if (clsName != null && clsName.length() > 0) {
164169
return createNewInstance(classLoader, clsName);

0 commit comments

Comments
 (0)