You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2019/06/27 13:45:56 UTC

[sling-org-apache-sling-connection-timeout-agent] 05/05: Fix or ignore some Sonar warnings

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

rombert pushed a commit to branch feature/osgi-fixes
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-connection-timeout-agent.git

commit 0f8511b1ac6f5786d14c35054b08d213a67620f3
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Jun 27 15:41:51 2019 +0200

    Fix or ignore some Sonar warnings
---
 src/main/java/org/apache/sling/cta/impl/Agent.java               | 9 +++++++--
 src/main/java/org/apache/sling/cta/impl/Log.java                 | 9 +++++----
 .../org/apache/sling/cta/impl/MBeanAwareTimeoutTransformer.java  | 4 ++--
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/sling/cta/impl/Agent.java b/src/main/java/org/apache/sling/cta/impl/Agent.java
index 3c5776b..d4d5ff2 100644
--- a/src/main/java/org/apache/sling/cta/impl/Agent.java
+++ b/src/main/java/org/apache/sling/cta/impl/Agent.java
@@ -28,7 +28,7 @@ import javax.management.MBeanRegistrationException;
 import javax.management.NotCompliantMBeanException;
 
 public class Agent {
-
+    
     public static void premain(String args, Instrumentation inst) {
         
         String[] parsedArgs = args != null ? args.split(",") : new String[0];
@@ -68,5 +68,10 @@ public class Agent {
         }
 
         Log.get().log("All transformers installed");
-    }    
+    }
+    
+    // prevent instantiation
+    private Agent() {
+        
+    }
 }
diff --git a/src/main/java/org/apache/sling/cta/impl/Log.java b/src/main/java/org/apache/sling/cta/impl/Log.java
index e0e3213..0b7f4e3 100644
--- a/src/main/java/org/apache/sling/cta/impl/Log.java
+++ b/src/main/java/org/apache/sling/cta/impl/Log.java
@@ -32,7 +32,7 @@ import java.util.Formatter;
  */
 abstract class Log {
     
-    private static Log INSTANCE;
+    private static Log INSTANCE; // NOSONAR - name is OK for static fields
 
     /**
      * Configures the global logger instance
@@ -87,13 +87,14 @@ abstract class Log {
 
         @Override
         public void log(String msg, Object... args) {
-            System.out.format(LOG_ENTRY_PREFIX + msg + " %n", args);
+            System.out.format(LOG_ENTRY_PREFIX + msg + " %n", args); // NOSONAR - this is a logger, OK to use System.out
         }
         
         @Override
         public void fatal(String msg, Throwable t) {
-            t.printStackTrace(); // ensure _something_ is printed
-            throw new RuntimeException(LOG_ENTRY_PREFIX + msg, t);
+            // ensure _something_ is printed, throwable might not be printed
+            t.printStackTrace(); // NOSONAR - OK to use printStackTrace, we are a logger
+            throw new RuntimeException(LOG_ENTRY_PREFIX + msg, t); // NOSONAR - we don't want custom exceptions
             
         }
     }
diff --git a/src/main/java/org/apache/sling/cta/impl/MBeanAwareTimeoutTransformer.java b/src/main/java/org/apache/sling/cta/impl/MBeanAwareTimeoutTransformer.java
index d30745a..d3118f0 100644
--- a/src/main/java/org/apache/sling/cta/impl/MBeanAwareTimeoutTransformer.java
+++ b/src/main/java/org/apache/sling/cta/impl/MBeanAwareTimeoutTransformer.java
@@ -64,7 +64,7 @@ public abstract class MBeanAwareTimeoutTransformer implements ClassFileTransform
             return classfileBuffer;
         } catch (Exception e) {
             Log.get().fatal("Transformation failed", e);
-            return null;
+            return null; // NOSONAR: null return is OK in case no transform is performed
         }
     }
 
@@ -75,6 +75,6 @@ public abstract class MBeanAwareTimeoutTransformer implements ClassFileTransform
      * @return the new class definition
      * @throws Exception in case of any problems while transforming
      */
-    protected abstract byte[] doTransformClass(CtClass cc) throws Exception;
+    protected abstract byte[] doTransformClass(CtClass cc) throws Exception; // NOSONAR - throwing Exception is OK, we don't want custom exceptions
 
 }
\ No newline at end of file