You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/17 15:23:21 UTC

[tomcat] branch main updated: Refactor to simplify the code

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

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


The following commit(s) were added to refs/heads/main by this push:
     new e6c7d8d6d5 Refactor to simplify the code
e6c7d8d6d5 is described below

commit e6c7d8d6d506eee8c351393d898a15b405d2c3da
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jun 17 16:22:43 2022 +0100

    Refactor to simplify the code
    
    The original cache implementation set these fields to null when the
    cache was invalidated. Hence the NPE protection was required. That is no
    longer the case so the protection can be removed.
---
 .../apache/catalina/webresources/CachedResource.java  | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java
index ea15590963..960571c7c5 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -184,61 +184,48 @@ public class CachedResource implements WebResource {
 
     @Override
     public long getLastModified() {
-        Long cachedLastModified = this.cachedLastModified;
         if (cachedLastModified == null) {
-            cachedLastModified =
-                    Long.valueOf(webResource.getLastModified());
-            this.cachedLastModified = cachedLastModified;
+            cachedLastModified = Long.valueOf(webResource.getLastModified());
         }
         return cachedLastModified.longValue();
     }
 
     @Override
     public String getLastModifiedHttp() {
-        String cachedLastModifiedHttp = this.cachedLastModifiedHttp;
         if (cachedLastModifiedHttp == null) {
             cachedLastModifiedHttp = webResource.getLastModifiedHttp();
-            this.cachedLastModifiedHttp = cachedLastModifiedHttp;
         }
         return cachedLastModifiedHttp;
     }
 
     @Override
     public boolean exists() {
-        Boolean cachedExists = this.cachedExists;
         if (cachedExists == null) {
             cachedExists = Boolean.valueOf(webResource.exists());
-            this.cachedExists = cachedExists;
         }
         return cachedExists.booleanValue();
     }
 
     @Override
     public boolean isVirtual() {
-        Boolean cachedIsVirtual = this.cachedIsVirtual;
         if (cachedIsVirtual == null) {
             cachedIsVirtual = Boolean.valueOf(webResource.isVirtual());
-            this.cachedIsVirtual = cachedIsVirtual;
         }
         return cachedIsVirtual.booleanValue();
     }
 
     @Override
     public boolean isDirectory() {
-        Boolean cachedIsDirectory = this.cachedIsDirectory;
         if (cachedIsDirectory == null) {
             cachedIsDirectory = Boolean.valueOf(webResource.isDirectory());
-            this.cachedIsDirectory = cachedIsDirectory;
         }
         return cachedIsDirectory.booleanValue();
     }
 
     @Override
     public boolean isFile() {
-        Boolean cachedIsFile = this.cachedIsFile;
         if (cachedIsFile == null) {
             cachedIsFile = Boolean.valueOf(webResource.isFile());
-            this.cachedIsFile = cachedIsFile;
         }
         return cachedIsFile.booleanValue();
     }
@@ -259,13 +246,11 @@ public class CachedResource implements WebResource {
 
     @Override
     public long getContentLength() {
-        Long cachedContentLength = this.cachedContentLength;
         if (cachedContentLength == null) {
             long result = 0;
             if (webResource != null) {
                 result = webResource.getContentLength();
                 cachedContentLength = Long.valueOf(result);
-                this.cachedContentLength = cachedContentLength;
             }
             return result;
         }
@@ -314,13 +299,11 @@ public class CachedResource implements WebResource {
 
     @Override
     public byte[] getContent() {
-        byte[] cachedContent = this.cachedContent;
         if (cachedContent == null) {
             if (getContentLength() > objectMaxSizeBytes) {
                 return null;
             }
             cachedContent = webResource.getContent();
-            this.cachedContent = cachedContent;
         }
         return cachedContent;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org