Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Minor
    • Resolution: Implemented
    • Affects Version/s: Trunk
    • Fix Version/s: Upcoming Release
    • Component/s: framework
    • Labels:
      None

      Description

      • GenericEngineFactory.java:67, REC_CATCH_EXCEPTION
        REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.service.engine.GenericEngineFactory.getGenericEngine(String)

      This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try

      { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

      A better approach is to either explicitly catch the specific exceptions that are thrown, or to explicitly catch RuntimeException exception, rethrow it, and then catch all non-Runtime Exceptions, as shown below:

      try { ... } catch (RuntimeException e) { throw e; } catch (Exception e) { ... deal with all non-runtime exceptions ... }

      - GroovyEngine.java:-1, CI_CONFUSED_INHERITANCE
      CI: Class org.apache.ofbiz.service.engine.GroovyEngine is final but declares protected field org.apache.ofbiz.service.engine.GroovyEngine.EMPTY_ARGS

      This class is declared to be final, but declares fields to be protected. Since the class is final, it can not be derived from, and the use of protected is confusing. The access modifier for the field should be changed to private or public to represent the true use for the field.

      - HttpEngine.java:64, REC_CATCH_EXCEPTION
      REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.service.engine.HttpEngine.runSync(String, ModelService, Map)

      This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... }

      catch (Exception e)

      { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

      A better approach is to either explicitly catch the specific exceptions that are thrown, or to explicitly catch RuntimeException exception, rethrow it, and then catch all non-Runtime Exceptions, as shown below:

      try { ... } catch (RuntimeException e) { throw e; } catch (Exception e) { ... deal with all non-runtime exceptions ... }

      - HttpEngine.java:137, REC_CATCH_EXCEPTION
      REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.service.engine.HttpEngine.httpEngine(HttpServletRequest, HttpServletResponse)

      This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something }

      as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

      A better approach is to either explicitly catch the specific exceptions that are thrown, or to explicitly catch RuntimeException exception, rethrow it, and then catch all non-Runtime Exceptions, as shown below:

      try

      { ... } catch (RuntimeException e) { throw e; } catch (Exception e) { ... deal with all non-runtime exceptions ... }

      - HttpEngine.java:185, DM_DEFAULT_ENCODING
      Dm: Found reliance on default encoding in org.apache.ofbiz.service.engine.HttpEngine.httpEngine(HttpServletRequest, HttpServletResponse): String.getBytes()

      Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

      - SOAPClientEngine.java:135, REC_CATCH_EXCEPTION
      REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.service.engine.SOAPClientEngine.serviceInvoker(ModelService, Map)

      This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.

      A better approach is to either explicitly catch the specific exceptions that are thrown, or to explicitly catch RuntimeException exception, rethrow it, and then catch all non-Runtime Exceptions, as shown below:

      try { ... }

      catch (RuntimeException e)

      { throw e; }

      catch (Exception e) {
      ... deal with all non-runtime exceptions ...

        Activity

        Hide
        Dennis Balkir Dennis Balkir added a comment -
        • Diamond Operators fixed

        class GroovyEngine:

        • Line 51: changed the parameter from protected to private

        class HttpEngine:

        • Line 191: added a Charset to getByte
        • Line 194: added a Charset to getByte
        Show
        Dennis Balkir Dennis Balkir added a comment - Diamond Operators fixed class GroovyEngine: Line 51: changed the parameter from protected to private class HttpEngine: Line 191: added a Charset to getByte Line 194: added a Charset to getByte
        Hide
        mbrohl Michael Brohl added a comment -

        Thanks Dennis,

        your patch is in trunk r1811468.

        Show
        mbrohl Michael Brohl added a comment - Thanks Dennis, your patch is in trunk r1811468.

          People

          • Assignee:
            mbrohl Michael Brohl
            Reporter:
            Dennis Balkir Dennis Balkir
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development