HHH-9422 Metamodel Generator should close streams opened to persistence.xml and referenced mapping files

This commit is contained in:
Sanne Grinovero 2020-09-02 12:16:41 +01:00
parent 162bc7d9dd
commit ea24abd757
1 changed files with 21 additions and 20 deletions

View File

@ -108,7 +108,7 @@ public class JpaDescriptorParser {
private Persistence getPersistence() {
Persistence persistence = null;
String persistenceXmlLocation = context.getPersistenceXmlLocation();
InputStream stream = xmlParserHelper.getInputStreamForResource( persistenceXmlLocation );
final InputStream stream = xmlParserHelper.getInputStreamForResource( persistenceXmlLocation );
if ( stream == null ) {
return null;
}
@ -122,12 +122,13 @@ public class JpaDescriptorParser {
Diagnostic.Kind.WARNING, "Unable to parse persistence.xml: " + e.getMessage()
);
}
try {
stream.close();
}
catch (IOException e) {
// eat it
finally {
try {
stream.close();
}
catch (IOException e) {
// eat it
}
}
return persistence;
@ -135,29 +136,29 @@ public class JpaDescriptorParser {
private void loadEntityMappings(Collection<String> mappingFileNames) {
for ( String mappingFile : mappingFileNames ) {
InputStream stream = xmlParserHelper.getInputStreamForResource( mappingFile );
final InputStream stream = xmlParserHelper.getInputStreamForResource( mappingFile );
if ( stream == null ) {
continue;
}
EntityMappings mapping = null;
try {
Schema schema = xmlParserHelper.getSchema( ORM_SCHEMA );
mapping = xmlParserHelper.getJaxbRoot( stream, EntityMappings.class, schema );
final Schema schema = xmlParserHelper.getSchema( ORM_SCHEMA );
final EntityMappings mapping = xmlParserHelper.getJaxbRoot( stream, EntityMappings.class, schema );
if ( mapping != null ) {
entityMappings.add( mapping );
}
}
catch (XmlParsingException e) {
context.logMessage(
Diagnostic.Kind.WARNING, "Unable to parse " + mappingFile + ": " + e.getMessage()
);
}
if ( mapping != null ) {
entityMappings.add( mapping );
}
try {
stream.close();
}
catch (IOException e) {
// eat it
finally {
try {
stream.close();
}
catch (IOException e) {
// eat it
}
}
}
}