jenkinsci/hpe-application-automation-tools-plugin

View on GitHub
src/main/java/com/microfocus/application/automation/tools/run/RunFromAlmBuilder.java

Summary

Maintainability
A
3 hrs
Test Coverage

Avoid too many return statements within this method.
Open

                return;

    Avoid too many return statements within this method.
    Open

                return;

      Avoid too many return statements within this method.
      Open

                  return;

        Avoid too many return statements within this method.
        Open

                    return;

          Avoid too many return statements within this method.
          Open

                      return;

            Constructor has 19 parameters, which is greater than 7 authorized.
            Open

                public RunFromAlmBuilder(

            A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

            Noncompliant Code Example

            With a maximum number of 4 parameters:

            public void doSomething(int param1, int param2, int param3, String param4, long param5) {
            ...
            }
            

            Compliant Solution

            public void doSomething(int param1, int param2, int param3, String param4) {
            ...
            }
            

            Exceptions

            Methods annotated with :

            • Spring's @RequestMapping (and related shortcut annotations, like @GetRequest)
            • JAX-RS API annotations (like @javax.ws.rs.GET)
            • Bean constructor injection with @org.springframework.beans.factory.annotation.Autowired
            • CDI constructor injection with @javax.inject.Inject
            • @com.fasterxml.jackson.annotation.JsonCreator

            may have a lot of parameters, encapsulation being possible. Such methods are therefore ignored.

            Refactor this method to reduce its Cognitive Complexity from 28 to the 15 allowed.
            Open

                public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener)

            Cognitive Complexity is a measure of how hard the control flow of a method is to understand. Methods with high Cognitive Complexity will be difficult to maintain.

            See

            Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
            Open

                    } catch (IOException | InterruptedException e) {

            InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the fact that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.

            Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:

            If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

            Noncompliant Code Example

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) { // Noncompliant; logging is not enough
                LOGGER.log(Level.WARN, "Interrupted!", e);
              }
            }
            

            Compliant Solution

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) {
                LOGGER.log(Level.WARN, "Interrupted!", e);
                // Restore interrupted state...
                Thread.currentThread().interrupt();
              }
            }
            

            See

            Rename "almServerSettingsModel" which hides the field declared at line 80.
            Open

                    AlmServerSettingsModel almServerSettingsModel = getAlmServerSettingsModel();

            Overriding or shadowing a variable declared in an outer scope can strongly impact the readability, and therefore the maintainability, of a piece of code. Further, it could lead maintainers to introduce bugs because they think they're using one variable but are really using another.

            Noncompliant Code Example

            class Foo {
              public int myField;
            
              public void doSomething() {
                int myField = 0;
                ...
              }
            }
            

            See

            Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
            Open

                    } catch (InterruptedException e) {

            InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the fact that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.

            Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:

            If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

            Noncompliant Code Example

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) { // Noncompliant; logging is not enough
                LOGGER.log(Level.WARN, "Interrupted!", e);
              }
            }
            

            Compliant Solution

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) {
                LOGGER.log(Level.WARN, "Interrupted!", e);
                // Restore interrupted state...
                Thread.currentThread().interrupt();
              }
            }
            

            See

            Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
            Open

                        } catch (InterruptedException e1) {

            InterruptedExceptions should never be ignored in the code, and simply logging the exception counts in this case as "ignoring". The throwing of the InterruptedException clears the interrupted state of the Thread, so if the exception is not handled properly the fact that the thread was interrupted will be lost. Instead, InterruptedExceptions should either be rethrown - immediately or after cleaning up the method's state - or the thread should be re-interrupted by calling Thread.interrupt() even if this is supposed to be a single-threaded application. Any other course of action risks delaying thread shutdown and loses the information that the thread was interrupted - probably without finishing its task.

            Similarly, the ThreadDeath exception should also be propagated. According to its JavaDoc:

            If ThreadDeath is caught by a method, it is important that it be rethrown so that the thread actually dies.

            Noncompliant Code Example

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) { // Noncompliant; logging is not enough
                LOGGER.log(Level.WARN, "Interrupted!", e);
              }
            }
            

            Compliant Solution

            public void run () {
              try {
                while (true) {
                  // do stuff
                }
              }catch (InterruptedException e) {
                LOGGER.log(Level.WARN, "Interrupted!", e);
                // Restore interrupted state...
                Thread.currentThread().interrupt();
              }
            }
            

            See

            This block of commented-out lines of code should be removed.
            Open

                    //KillFileName = "stop" + time + ".txt";

            Programmers should not comment out code as it bloats programs and reduces readability.

            Unused code should be deleted and can be retrieved from source control history if required.

            This block of commented-out lines of code should be removed.
            Open

                public void setRunFromAlmModel(RunFromAlmModel runFromAlmModel){

            Programmers should not comment out code as it bloats programs and reduces readability.

            Unused code should be deleted and can be retrieved from source control history if required.

            Remove this unused "almServerSettingsModel" private field.
            Open

                private AlmServerSettingsModel almServerSettingsModel;

            If a private field is declared but not used in the program, it can be considered dead code and should therefore be removed. This will improve maintainability because developers will not wonder what the variable is used for.

            Note that this rule does not take reflection into account, which means that issues will be raised on private fields that are only accessed using the reflection API.

            Noncompliant Code Example

            public class MyClass {
              private int foo = 42;
            
              public int compute(int a) {
                return a * 42;
              }
            
            }
            

            Compliant Solution

            public class MyClass {
              public int compute(int a) {
                return a * 42;
              }
            }
            

            Exceptions

            The Java serialization runtime associates with each serializable class a version number, called serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization.

            A serializable class can declare its own serialVersionUID explicitly by declaring a field named serialVersionUID that must be static, final, and of type long. By definition those serialVersionUID fields should not be reported by this rule:

            public class MyClass implements java.io.Serializable {
              private static final long serialVersionUID = 42L;
            }
            

            Moreover, this rule doesn't raise any issue on annotated fields.

            Replace this call to "replaceAll()" by a call to the "replace()" method.
            Open

                        String[] testSetsArr = value.replaceAll("\r", "").split("\n");

            The underlying implementation of String::replaceAll calls the java.util.regex.Pattern.compile() method each time it is called even if the first argument is not a regular expression. This has a significant performance cost and therefore should be used with care.

            When String::replaceAll is used, the first argument should be a real regular expression. If it’s not the case, String::replace does exactly the same thing as String::replaceAll without the performance drawback of the regex.

            This rule raises an issue for each String::replaceAll used with a String as first parameter which doesn’t contains special regex character or pattern.

            Noncompliant Code Example

            String init = "Bob is a Bird... Bob is a Plane... Bob is Superman!";
            String changed = init.replaceAll("Bob is", "It's"); // Noncompliant
            changed = changed.replaceAll("\\.\\.\\.", ";"); // Noncompliant
            

            Compliant Solution

            String init = "Bob is a Bird... Bob is a Plane... Bob is Superman!";
            String changed = init.replace("Bob is", "It's");
            changed = changed.replace("...", ";");
            

            Or, with a regex:

            String init = "Bob is a Bird... Bob is a Plane... Bob is Superman!";
            String changed = init.replaceAll("\\w*\\sis", "It's");
            changed = changed.replaceAll("\\.{3}", ";");
            

            See

            • {rule:java:S4248} - Regex patterns should not be created needlessly

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                        try {
                            AlmToolsUtils.runHpToolsAborterOnBuildEnv(build, launcher, listener, propsFileName, workspace);
                        } catch (IOException e1) {
                            Util.displayIOException(e1, listener);
                            build.setResult(Result.FAILURE);
            src/main/java/com/microfocus/application/automation/tools/run/RunFromFileBuilder.java on lines 921..928

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 62.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                    try {
                        strProps = AlmToolsUtils.getPropsAsString(mergedProps);
                    } catch (IOException e) {
                        build.setResult(Result.FAILURE);
                        listener.error("Failed to store properties on agent machine: " + e);
            src/main/java/com/microfocus/application/automation/tools/octane/testrunner/TestsToRunConverterBuilder.java on lines 289..295
            src/main/java/com/microfocus/application/automation/tools/run/RunFromFileBuilder.java on lines 859..865

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 44.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status