[jira] [Created] (OFBIZ-9706) [FB] Package org.apache.ofbiz.entity.test

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (OFBIZ-9706) [FB] Package org.apache.ofbiz.entity.test

Nicolas Malin (Jira)
Julian Leichert created OFBIZ-9706:
--------------------------------------

             Summary: [FB] Package org.apache.ofbiz.entity.test
                 Key: OFBIZ-9706
                 URL: https://issues.apache.org/jira/browse/OFBIZ-9706
             Project: OFBiz
          Issue Type: Sub-task
    Affects Versions: Trunk
            Reporter: Julian Leichert
            Priority: Minor


EntityQueryTestSuite.java:313, REC_CATCH_EXCEPTION
- REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.entity.test.EntityQueryTestSuite.testQueryIterator()

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 ...
  }

EntityQueryTestSuite.java:348, REC_CATCH_EXCEPTION
- REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.entity.test.EntityQueryTestSuite.testCursorForwardOnly()

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 ...
  }

EntityQueryTestSuite.java:383, REC_CATCH_EXCEPTION
- REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.entity.test.EntityQueryTestSuite.testCursorScrollSensitive()

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 ...
  }

EntityQueryTestSuite.java:418, REC_CATCH_EXCEPTION
- REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.entity.test.EntityQueryTestSuite.testCursorScrollInSensitive()

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 ...
  }

EntityTestSuite.java:462, DM_STRING_TOSTRING
- Dm: org.apache.ofbiz.entity.test.EntityTestSuite.testCountViews() invokes toString() method on a String

Calling String.toString() is just a redundant operation. Just use the String.

EntityTestSuite.java:1201, SIC_INNER_SHOULD_BE_STATIC_ANON
- SIC: The class org.apache.ofbiz.entity.test.EntityTestSuite$1 could be refactored into a named _static_ inner class

This class is an inner class, but does not use its embedded reference to the object which created it.  This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.  If possible, the class should be made into a static inner class. Since anonymous inner classes cannot be marked as static, doing this will require refactoring the inner class so that it is a named inner class.

EntityTestSuite.java:1215, SIC_INNER_SHOULD_BE_STATIC_ANON
- SIC: The class org.apache.ofbiz.entity.test.EntityTestSuite$2 could be refactored into a named _static_ inner class

This class is an inner class, but does not use its embedded reference to the object which created it.  This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.  If possible, the class should be made into a static inner class. Since anonymous inner classes cannot be marked as static, doing this will require refactoring the inner class so that it is a named inner class.

EntityTestSuite.java:1260, REC_CATCH_EXCEPTION
- REC: Exception is caught when Exception is not thrown in org.apache.ofbiz.entity.test.EntityTestSuite.testOneBigTransactionIsFasterThanSeveralSmallOnes()

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 ...
  }

EntityTestSuite.java:1263, DE_MIGHT_IGNORE
- DE: org.apache.ofbiz.entity.test.EntityTestSuite.testOneBigTransactionIsFasterThanSeveralSmallOnes() might ignore java.lang.Exception

This method might ignore an exception.  In general, exceptions should be handled or reported in some way, or they should be thrown out of the method.

EntityTestSuite.java:1314, SIC_INNER_SHOULD_BE_STATIC
- SIC: Should org.apache.ofbiz.entity.test.EntityTestSuite$TestObserver be a _static_ inner class?

This class is an inner class, but does not use its embedded reference to the object which created it.  This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.  If possible, the class should be made static.

EntityTestSuite.java:1320, URF_UNREAD_FIELD
- UrF: Unread field: org.apache.ofbiz.entity.test.EntityTestSuite$TestObserver.observable

This field is never read.  Consider removing it from the class.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)