This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git


The following commit(s) were added to refs/heads/main by this push:
     new ca2cf96  Minor robustness improvement
ca2cf96 is described below

commit ca2cf96c3f19d72365f655adf165b4ddd6a6ab23
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 8 09:14:05 2026 +0100

    Minor robustness improvement
---
 .../org/apache/tomcat/jakartaee/Migration.java     | 104 ++++++++++-----------
 1 file changed, 49 insertions(+), 55 deletions(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/Migration.java 
b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
index dbace17..3ff780b 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/Migration.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/Migration.java
@@ -508,73 +508,67 @@ public class Migration {
 
             CacheEntry cacheEntry = null;
             SourceSpool sourceSpool = null;
-            if (isNestedArchive && cache != null) {
-                // Spool source so the cache hash can be computed and, on a 
cache
-                // miss, the source can be re-read for conversion. Data above
-                // TEMP_FILE_THRESHOLD is spooled to a temp file to avoid
-                // unbounded memory usage.
-                sourceSpool = new SourceSpool(profile);
-                try {
+            try {
+                if (isNestedArchive && cache != null) {
+                    // Spool source so the cache hash can be computed and, on 
a cache
+                    // miss, the source can be re-read for conversion. Data 
above
+                    // TEMP_FILE_THRESHOLD is spooled to a temp file to avoid
+                    // unbounded memory usage.
+                    sourceSpool = new SourceSpool(profile);
                     IOUtils.copy(src, sourceSpool);
-                } catch (IOException e) {
-                    sourceSpool.discard();
-                    throw e;
-                }
-                String hash = sourceSpool.getHash();
+                    String hash = sourceSpool.getHash();
 
-                // Get cache entry (marks as accessed)
-                cacheEntry = cache.getCacheEntry(hash);
+                    // Get cache entry (marks as accessed)
+                    cacheEntry = cache.getCacheEntry(hash);
 
-                if (cacheEntry.exists()) {
-                    try {
+                    if (cacheEntry.exists()) {
                         // Cache hit! Copy cached result to dest and return
                         logger.log(Level.INFO, sm.getString("cache.hit", name, 
hash));
                         cacheEntry.copyToDestination(dest);
-                    } finally {
-                        sourceSpool.discard();
+                        // Although it is from the cache, this still counts as 
converting the source
+                        return true;
                     }
-                    // Although it is from the cache, this still counts as 
converting the source
-                    return true;
-                }
-
-                // Cache miss - use spooled source for conversion
-                logger.log(Level.FINE, sm.getString("cache.miss", name, hash));
-                src = sourceSpool.toInputStream();
-            }
 
-            // Process archive - stream directly to destination (and cache if 
needed)
-            try {
-                OutputStream targetOutputStream = dest;
-                if (cacheEntry != null) {
-                    // Tee output to both destination and cache temp file
-                    targetOutputStream = new 
org.apache.commons.io.output.TeeOutputStream(dest, cacheEntry.beginStore());
+                    // Cache miss - use spooled source for conversion
+                    logger.log(Level.FINE, sm.getString("cache.miss", name, 
hash));
+                    src = sourceSpool.toInputStream();
                 }
 
-                if (zipInMemory) {
-                    logger.log(Level.INFO, 
sm.getString("migration.archive.memory", name));
-                    convertedStream = migrateArchiveInMemory(src, 
targetOutputStream);
-                    logger.log(Level.INFO, 
sm.getString("migration.archive.complete", name));
-                } else {
-                    logger.log(Level.INFO, 
sm.getString("migration.archive.stream", name));
-                    convertedStream = migrateArchiveStreaming(src, 
targetOutputStream);
-                    logger.log(Level.INFO, 
sm.getString("migration.archive.complete", name));
-                }
+                // Process archive - stream directly to destination (and cache 
if needed)
+                try {
+                    OutputStream targetOutputStream = dest;
+                    if (cacheEntry != null) {
+                        // Tee output to both destination and cache temp file
+                        targetOutputStream =
+                                new 
org.apache.commons.io.output.TeeOutputStream(dest, cacheEntry.beginStore());
+                    }
 
-                // Commit to cache on success
-                if (cacheEntry != null) {
-                    cacheEntry.commitStore();
-                    logger.log(Level.FINE, sm.getString("cache.store", 
cacheEntry.getHash(),
-                            Long.valueOf(cacheEntry.getFileSize())));
-                }
-            } catch (Exception e) {
-                // Rollback cache on error
-                if (cacheEntry != null) {
-                    cacheEntry.rollbackStore();
-                }
-                if (e instanceof IOException) {
-                    throw (IOException) e;
+                    if (zipInMemory) {
+                        logger.log(Level.INFO, 
sm.getString("migration.archive.memory", name));
+                        convertedStream = migrateArchiveInMemory(src, 
targetOutputStream);
+                        logger.log(Level.INFO, 
sm.getString("migration.archive.complete", name));
+                    } else {
+                        logger.log(Level.INFO, 
sm.getString("migration.archive.stream", name));
+                        convertedStream = migrateArchiveStreaming(src, 
targetOutputStream);
+                        logger.log(Level.INFO, 
sm.getString("migration.archive.complete", name));
+                    }
+
+                    // Commit to cache on success
+                    if (cacheEntry != null) {
+                        cacheEntry.commitStore();
+                        logger.log(Level.FINE, sm.getString("cache.store", 
cacheEntry.getHash(),
+                                Long.valueOf(cacheEntry.getFileSize())));
+                    }
+                } catch (Exception e) {
+                    // Rollback cache on error
+                    if (cacheEntry != null) {
+                        cacheEntry.rollbackStore();
+                    }
+                    if (e instanceof IOException) {
+                        throw (IOException) e;
+                    }
+                    throw e;
                 }
-                throw e;
             } finally {
                 if (sourceSpool != null) {
                     sourceSpool.discard();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to