HHH-11718 - Fix various alerts reported by lgtm.com
Fpr more details:06f0c3acb2/files/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/SchemaUpdateTask.java (V218)
06f0c3acb2/files/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ExplodedArchiveDescriptor.java (V149)
06f0c3acb2/files/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/JarFileBasedArchiveDescriptor.java (V74)
This commit is contained in:
parent
2d4600bbc7
commit
72e0d593b9
|
@ -145,8 +145,7 @@ public class ExplodedArchiveDescriptor extends AbstractArchiveDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processZippedRoot(File rootFile, ArchiveContext context) {
|
private void processZippedRoot(File rootFile, ArchiveContext context) {
|
||||||
try {
|
try (final JarFile jarFile = new JarFile(rootFile)){
|
||||||
final JarFile jarFile = new JarFile(rootFile);
|
|
||||||
final Enumeration<? extends ZipEntry> entries = jarFile.entries();
|
final Enumeration<? extends ZipEntry> entries = jarFile.entries();
|
||||||
while ( entries.hasMoreElements() ) {
|
while ( entries.hasMoreElements() ) {
|
||||||
final ZipEntry zipEntry = entries.nextElement();
|
final ZipEntry zipEntry = entries.nextElement();
|
||||||
|
|
|
@ -53,97 +53,106 @@ public class JarFileBasedArchiveDescriptor extends AbstractArchiveDescriptor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
|
try {
|
||||||
while ( zipEntries.hasMoreElements() ) {
|
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
|
||||||
final ZipEntry zipEntry = zipEntries.nextElement();
|
while ( zipEntries.hasMoreElements() ) {
|
||||||
final String entryName = extractName( zipEntry );
|
final ZipEntry zipEntry = zipEntries.nextElement();
|
||||||
|
final String entryName = extractName( zipEntry );
|
||||||
|
|
||||||
if ( getEntryBasePrefix() != null && ! entryName.startsWith( getEntryBasePrefix() ) ) {
|
if ( getEntryBasePrefix() != null && ! entryName.startsWith( getEntryBasePrefix() ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( zipEntry.isDirectory() ) {
|
if ( zipEntry.isDirectory() ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( entryName.equals( getEntryBasePrefix() ) ) {
|
if ( entryName.equals( getEntryBasePrefix() ) ) {
|
||||||
// exact match, might be a nested jar entry (ie from jar:file:..../foo.ear!/bar.jar)
|
// exact match, might be a nested jar entry (ie from jar:file:..../foo.ear!/bar.jar)
|
||||||
//
|
//
|
||||||
// This algorithm assumes that the zipped file is only the URL root (including entry), not
|
// This algorithm assumes that the zipped file is only the URL root (including entry), not
|
||||||
// just any random entry
|
// just any random entry
|
||||||
try (InputStream is = new BufferedInputStream( jarFile.getInputStream( zipEntry ) )) {
|
try ( final InputStream is = new BufferedInputStream( jarFile.getInputStream( zipEntry ) );
|
||||||
final JarInputStream jarInputStream = new JarInputStream( is );
|
final JarInputStream jarInputStream = new JarInputStream( is )) {
|
||||||
ZipEntry subZipEntry = jarInputStream.getNextEntry();
|
ZipEntry subZipEntry = jarInputStream.getNextEntry();
|
||||||
while ( subZipEntry != null ) {
|
while ( subZipEntry != null ) {
|
||||||
if ( ! subZipEntry.isDirectory() ) {
|
if ( ! subZipEntry.isDirectory() ) {
|
||||||
|
|
||||||
final String name = extractName( subZipEntry );
|
final String name = extractName( subZipEntry );
|
||||||
final String relativeName = extractRelativeName( subZipEntry );
|
final String relativeName = extractRelativeName( subZipEntry );
|
||||||
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( name, jarInputStream );
|
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess( name, jarInputStream );
|
||||||
|
|
||||||
final ArchiveEntry entry = new ArchiveEntry() {
|
final ArchiveEntry entry = new ArchiveEntry() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameWithinArchive() {
|
public String getNameWithinArchive() {
|
||||||
return relativeName;
|
return relativeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStreamAccess getStreamAccess() {
|
public InputStreamAccess getStreamAccess() {
|
||||||
return inputStreamAccess;
|
return inputStreamAccess;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
|
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
|
||||||
entryHandler.handleEntry( entry, context );
|
entryHandler.handleEntry( entry, context );
|
||||||
|
}
|
||||||
|
|
||||||
|
subZipEntry = jarInputStream.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new ArchiveException( "Error accessing JarFile entry [" + zipEntry.getName() + "]", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final String name = extractName( zipEntry );
|
||||||
|
final String relativeName = extractRelativeName( zipEntry );
|
||||||
|
final InputStreamAccess inputStreamAccess;
|
||||||
|
try (InputStream is = jarFile.getInputStream( zipEntry )) {
|
||||||
|
inputStreamAccess = buildByteBasedInputStreamAccess( name, is );
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new ArchiveException(
|
||||||
|
String.format(
|
||||||
|
"Unable to access stream from jar file [%s] for entry [%s]",
|
||||||
|
jarFile.getName(),
|
||||||
|
zipEntry.getName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArchiveEntry entry = new ArchiveEntry() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
subZipEntry = jarInputStream.getNextEntry();
|
@Override
|
||||||
}
|
public String getNameWithinArchive() {
|
||||||
}
|
return relativeName;
|
||||||
catch (Exception e) {
|
}
|
||||||
throw new ArchiveException( "Error accessing JarFile entry [" + zipEntry.getName() + "]", e );
|
|
||||||
|
@Override
|
||||||
|
public InputStreamAccess getStreamAccess() {
|
||||||
|
return inputStreamAccess;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
|
||||||
|
entryHandler.handleEntry( entry, context );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
final String name = extractName( zipEntry );
|
finally {
|
||||||
final String relativeName = extractRelativeName( zipEntry );
|
try {
|
||||||
final InputStreamAccess inputStreamAccess;
|
jarFile.close();
|
||||||
try (InputStream is = jarFile.getInputStream( zipEntry )) {
|
}
|
||||||
inputStreamAccess = buildByteBasedInputStreamAccess( name, is );
|
catch ( Exception ignore ) {
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new ArchiveException(
|
|
||||||
String.format(
|
|
||||||
"Unable to access stream from jar file [%s] for entry [%s]",
|
|
||||||
jarFile.getName(),
|
|
||||||
zipEntry.getName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ArchiveEntry entry = new ArchiveEntry() {
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNameWithinArchive() {
|
|
||||||
return relativeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStreamAccess getStreamAccess() {
|
|
||||||
return inputStreamAccess;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler( entry );
|
|
||||||
entryHandler.handleEntry( entry, context );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,10 @@ public class ExceptionConverterImpl implements ExceptionConverter {
|
||||||
public RuntimeException convertCommitException(RuntimeException e) {
|
public RuntimeException convertCommitException(RuntimeException e) {
|
||||||
if ( sharedSessionContract.getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
|
if ( sharedSessionContract.getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
|
||||||
Throwable wrappedException;
|
Throwable wrappedException;
|
||||||
if ( e instanceof PersistenceException ) {
|
if ( e instanceof HibernateException ) {
|
||||||
|
wrappedException = convert( (HibernateException) e );
|
||||||
|
}
|
||||||
|
else if ( e instanceof PersistenceException ) {
|
||||||
Throwable cause = e.getCause() == null ? e : e.getCause();
|
Throwable cause = e.getCause() == null ? e : e.getCause();
|
||||||
if ( cause instanceof HibernateException ) {
|
if ( cause instanceof HibernateException ) {
|
||||||
wrappedException = convert( (HibernateException) cause );
|
wrappedException = convert( (HibernateException) cause );
|
||||||
|
@ -59,9 +62,6 @@ public class ExceptionConverterImpl implements ExceptionConverter {
|
||||||
wrappedException = cause;
|
wrappedException = cause;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( e instanceof HibernateException ) {
|
|
||||||
wrappedException = convert( (HibernateException) e );
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
wrappedException = e;
|
wrappedException = e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,9 @@ public class SchemaUpdateTask extends MatchingTask {
|
||||||
properties.putAll( getProject().getProperties() );
|
properties.putAll( getProject().getProperties() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
properties.load( new FileInputStream( propertiesFile ) );
|
try (FileInputStream fip = new FileInputStream( propertiesFile )){
|
||||||
|
properties.load( fip );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registryBuilder.applySettings( properties );
|
registryBuilder.applySettings( properties );
|
||||||
|
|
Loading…
Reference in New Issue