[jira] [Created] (OPENJPA-2702) Possible bugs in the source code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Created] (OPENJPA-2702) Possible bugs in the source code

JIRA jira@apache.org
AppChecker created OPENJPA-2702:
-----------------------------------

             Summary: Possible bugs in the source code
                 Key: OPENJPA-2702
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2702
             Project: OpenJPA
          Issue Type: Bug
          Components: integration, jdbc, xml store
    Affects Versions: 2.4.2
            Reporter: AppChecker


Hi!
I've checked your project with static analyzer [AppChecker|npo-echelon.ru/en/solutions/appchecker.php] and it found several suspicious code fragments:

1) [openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java#L1569-L1570]


{code:java}
        if (!StringUtil.isEmpty(name));
            col.setIdentifier(DBIdentifier.newColumn(name, delimit()));
{code}
if-statement is empty and contains only ";"

2) [src/main/java/org/apache/openjpa/persistence/util/SourceCode.java#L812|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java#L812]


{code:java}
StringBuilder tmp = new StringBuilder(BLOCK_DELIMITER.start);
{code}
BLOCK_DELIMITER.start has type 'char'
StringBuilder constructor with a char argument constructs a string with no characters in it ( this argument specified initial capacity) .
Example - http://ideone.com/kVPY0P

3)[openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L875|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L875]

{code:java}
        new RuntimeException("TradeJPADirect:resetTrade - not implemented in JPA mode");

{code}
Exception is created, but not thrown.
Same:
* [openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L979|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L979]
* [openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L990|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-integration/daytrader/src/test/java/org/apache/openjpa/integration/daytrader/TradeJPADirect.java#L990]

4) [openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java#L115-L118|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java#L115-L118]


{code:java}
                // remove any duplicate kodo/openjpa property so we don't clash
                if (props[i].startsWith("openjpa."))
                    p.remove("openjpa." + props[i].substring(5));
                else if (props[i].startsWith("openjpa."))
                    p.remove("openjpa." + props[i].substring(8));
{code}
props[i].startsWith("openjpa.") is checked twice.
Same:
* [openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/BaseJDBCTest.java#L162-L166|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/BaseJDBCTest.java#L162-L166]
* [openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/BaseQueryTest.java#L129-L133|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/BaseQueryTest.java#L129-L133]
* [openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java#L625-L632|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java#L625-L632]

5) [openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/NameValidator.java#L30|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/NameValidator.java#L30]


{code:java}
if(obj.getName().equals("") || obj.getName() == null)
{code}

Strange that 'obj.getName()' is used and then is checked to null.
Same:
[openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/LongNameValidator.java#L30|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/LongNameValidator.java#L30]
[openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/ddtype/NameValidator.java#L29|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/ddtype/NameValidator.java#L29]
[openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/ddtype/LongNameValidator.java#L29|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/ddtype/LongNameValidator.java#L29]

6) [openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/VC.java#L115|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/VC.java#L115]


{code:java}
                (this.getVcId() == null &&
                this.getVcId().equals(id.getVcId())
{code}
if this.getVcId() is null, method this.getVcId().equals will be invoked, so NPE will be thrown.

7) [openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java#L126-L127|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualTypeExpression.java#L126-L127]
{code:java}
        ClassMapping cm1 = (ClassMapping)((val1 instanceof Type) ? val1.getMetaData() :
            val1.getMetaData());
{code}
The parts of the ternary operator are same.
Same:
[openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java#L127-L128|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualTypeExpression.java#L127-L128]

8) [openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java#L424-L428|https://github.com/apache/openjpa/blob/49c1478cf3f107d9f7069bf2102d8cf0b6ca2b12/openjpa-xmlstore/src/main/java/org/apache/openjpa/xmlstore/XMLFileHandler.java#L424-L428]
Is it fallthrough? Or 'break' keyword is omitted?

I hope this will be useful



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