You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ad...@apache.org on 2021/01/30 11:02:39 UTC

[roller] branch master updated: Fixed: sonarqube issue - Methods returns should not be invariant When a method is designed to return an invariant value, it may be poor design, but it shouldn't adversely affect the outcome of your program. However, when it happens on all paths through the logic, it is surely a bug.

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

adityasharma pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c65285  Fixed: sonarqube issue - Methods returns should not be invariant When a method is designed to return an invariant value, it may be poor design, but it shouldn't adversely affect the outcome of your program. However, when it happens on all paths through the logic, it is surely a bug.
4c65285 is described below

commit 4c652856e4cb4dba3c415144000d616f831e4857
Author: Aditya Sharma <ad...@apache.org>
AuthorDate: Sat Jan 30 16:31:06 2021 +0530

    Fixed: sonarqube issue - Methods returns should not be invariant
    When a method is designed to return an invariant value, it may be poor design, but it shouldn't adversely affect the outcome of your program. However, when it happens on all paths through the logic, it is surely a bug.
---
 .../atomprotocol/RollerAtomHandler.java            | 117 ++++++++++-----------
 1 file changed, 58 insertions(+), 59 deletions(-)

diff --git a/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java b/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
index f6a427e..e65102f 100644
--- a/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
+++ b/app/src/main/java/org/apache/roller/weblogger/webservices/atomprotocol/RollerAtomHandler.java
@@ -52,38 +52,38 @@ import org.apache.roller.weblogger.ui.core.RollerContext;
 
 /**
  * Weblogger's ROME Propono-based Atom Protocol implementation.
- * 
- * Each Weblogger workspace has two collections, one that accepts entries and 
- * that accepts everything. The entries collection represents the weblog 
- * entries in a single weblog and the everything collection represents that 
- * weblog's uploaded-files. 
- * 
+ *
+ * Each Weblogger workspace has two collections, one that accepts entries and
+ * that accepts everything. The entries collection represents the weblog
+ * entries in a single weblog and the everything collection represents that
+ * weblog's uploaded-files.
+ *
  * Here are the APP URIs suppored by Weblogger:
- * 
+ *
  * <pre>
  *    /roller-services/app
  *    Introspection doc
- * 
- * 
+ *
+ *
  *    /roller-services/app/[weblog-handle>/entries
  *    Entry collection for a weblog (GET, POST)
- * 
+ *
  *    /roller-services/app/[weblog-handle]/entries/[offset]
  *    Entry collection for a blog, with offset (GET)
- * 
+ *
  *    /roller-services/app/[weblog-handle]/entry/[id]
  *    Individual entry (GET, PUT, DELETE)
  *
- * 
+ *
  *    /roller-services/app/[weblog-handle]/resources
  *    Resource (i.e. file-uploads) collection for a weblog (GET, POST)
- * 
+ *
  *    /roller-services/app/[weblog-handle]/resources/[offset]
  *    Resource collection for a blog, with offset (GET)
- * 
+ *
  *    /roller-services/app/[weblog-handle]/resource/*.media-link[name]
  *    Individual resource metadata (GET, PUT, DELETE)
- * 
+ *
  *    /roller-services/app/[weblog-handle]/resource/[name]
  *    Individual resource data (GET)
  * </pre>
@@ -95,17 +95,17 @@ public class RollerAtomHandler implements AtomHandler {
     protected User user = null;
     protected int maxEntries = 20;
     protected String atomURL = null;
-    
+
     protected static final boolean THROTTLE;
-    
+
     protected static Log log =
             LogFactory.getFactory().getInstance(RollerAtomHandler.class);
-    
+
     static {
         THROTTLE = WebloggerConfig
             .getBooleanProperty("webservices.atomprotocol.oneSecondThrottle", true);
     }
-    
+
     //------------------------------------------------------------ construction
 
     /**
@@ -133,9 +133,9 @@ public class RollerAtomHandler implements AtomHandler {
                 this.user = roller.getUserManager().getUserByUserName(userName);
             } catch (Exception neverHappen) {
                 log.debug("Getting user", neverHappen);
-            } 
+            }
         }
-        
+
         atomURL = WebloggerFactory.getWeblogger().getUrlStrategy().getAtomProtocolURL(true);
     }
 
@@ -149,9 +149,9 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return ret;
     }
-    
+
     //----------------------------------------------------------- introspection
-    
+
     /**
      * Return Atom service document for site, getting blog-name from pathInfo.
      * The workspace will contain collections for entries, categories and resources.
@@ -164,7 +164,7 @@ public class RollerAtomHandler implements AtomHandler {
             throw new AtomException("ERROR creating Service Document", ex);
         }
     }
-     
+
     //----------------------------------------------------------------- create
 
     /**
@@ -174,8 +174,8 @@ public class RollerAtomHandler implements AtomHandler {
         EntryCollection ecol = new EntryCollection(user, atomURL);
         return ecol.postEntry(areq, entry);
     }
-    
-    
+
+
     /**
      * Create new resource in generic collection (a Weblogger blog has only one).
      * TODO: can we avoid saving temporary file?
@@ -187,10 +187,10 @@ public class RollerAtomHandler implements AtomHandler {
         MediaCollection mcol = new MediaCollection(user, atomURL);
         return mcol.postMedia(areq, entry);
     }
-    
 
-    //----------------------------------------------------------------- retrieve 
-    
+
+    //----------------------------------------------------------------- retrieve
+
     /**
      * Return collection specified by pathinfo.
      * <pre>
@@ -203,19 +203,19 @@ public class RollerAtomHandler implements AtomHandler {
      */
     public Feed getCollection(AtomRequest areq) throws AtomException {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
-        
+
         if (pathInfo.length > 0 && pathInfo[1].equals("entries")) {
             EntryCollection ecol = new EntryCollection(user, atomURL);
             return ecol.getCollection(areq);
-            
+
         } else if (pathInfo.length > 0 && pathInfo[1].equals("resources")) {
             MediaCollection mcol = new MediaCollection(user, atomURL);
             return mcol.getCollection(areq);
         }
         throw new AtomNotFoundException("Cannot find collection specified");
     }
-    
-       
+
+
     public Categories getCategories(AtomRequest arg0) throws AtomException {
         throw new UnsupportedOperationException("Not supported yet.");
     }
@@ -234,12 +234,12 @@ public class RollerAtomHandler implements AtomHandler {
                 return ecol.getEntry(areq);
             } else if (pathInfo[1].equals("resource") && pathInfo[pathInfo.length - 1].endsWith(".media-link")) {
                 MediaCollection mcol = new MediaCollection(user, atomURL);
-                return mcol.getEntry(areq);                    
+                return mcol.getEntry(areq);
             }
         }
         throw new AtomNotFoundException("Cannot find specified entry/resource");
     }
-    
+
     /**
      * Expects pathInfo of form /blog-name/resource/path/name
      */
@@ -247,10 +247,10 @@ public class RollerAtomHandler implements AtomHandler {
         MediaCollection mcol = new MediaCollection(user, atomURL);
         return mcol.getMediaResource(areq);
     }
-    
-    
+
+
     //----------------------------------------------------------------- update
-    
+
     /**
      * Update entry, URI like this /blog-name/entry/id
      */
@@ -268,10 +268,10 @@ public class RollerAtomHandler implements AtomHandler {
         MediaCollection mcol = new MediaCollection(user, atomURL);
         mcol.putMedia(areq);
     }
-    
-    
+
+
     //----------------------------------------------------------------- delete
-    
+
     /**
      * Delete entry, URI like this /blog-name/entry/id
      */
@@ -293,9 +293,9 @@ public class RollerAtomHandler implements AtomHandler {
         throw new AtomNotFoundException("cannot find specified entry/resource");
     }
 
-    
+
     //------------------------------------------------------------------ URI testers
-    
+
     /**
      * True if URL is the introspection URI.
      */
@@ -303,7 +303,7 @@ public class RollerAtomHandler implements AtomHandler {
         String[] pathInfo = StringUtils.split(areq.getPathInfo(),"/");
         return pathInfo.length == 0;
     }
-    
+
     /**
      * True if URL is a entry URI.
      */
@@ -317,7 +317,7 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return false;
     }
-        
+
     /**
      * True if URL is media edit URI. Media can be updated, but not metadata.
      */
@@ -328,7 +328,7 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return false;
     }
-        
+
     /**
      * True if URL is a collection URI of any sort.
      */
@@ -345,14 +345,14 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return false;
     }
-    
+
     public boolean isCategoriesURI(AtomRequest arg0) {
         return false;
     }
 
-    
+
     //------------------------------------------------------------------ permissions
-    
+
     /**
      * Return true if user is allowed to edit an entry.
      */
@@ -364,7 +364,7 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return false;
     }
-    
+
     /**
      * Return true if user is allowed to create/edit weblog entries and file uploads in a website.
      */
@@ -376,34 +376,33 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return false;
     }
-    
+
     /**
      * Return true if user is allowed to view an entry.
      */
     public static boolean canView(User u, WeblogEntry entry) {
         return canEdit(u, entry);
     }
-    
+
     /**
      * Return true if user is allowed to view a website.
      */
     public static boolean canView(User u, Weblog website) {
         return canEdit(u, website);
     }
-    
+
     //-------------------------------------------------------------- authentication
-    
+
     /**
      * Perform WSSE authentication based on information in request.
      * Will not work if Weblogger password encryption is turned on.
      */
     protected String authenticateWSSE(HttpServletRequest request) {
         String wsseHeader = request.getHeader("X-WSSE");
+        String ret = null;
         if (wsseHeader == null) {
-            return null;
+            return ret;
         }
-        
-        String ret = null;
         String userName = null;
         String created = null;
         String nonce = null;
@@ -441,7 +440,7 @@ public class RollerAtomHandler implements AtomHandler {
         }
         return ret;
     }
-    
+
     /**
      * BASIC authentication.
      */
@@ -478,7 +477,7 @@ public class RollerAtomHandler implements AtomHandler {
         return null;
     }
 
-    
+
     private String authenticationOAUTH(
             HttpServletRequest request, HttpServletResponse response) {
         try {