Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2702

Possible bugs in the source code

    XMLWordPrintableJSON

    Details

      Description

      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

              if (!StringUtil.isEmpty(name));
                  col.setIdentifier(DBIdentifier.newColumn(name, delimit()));
      

      if-statement is empty and contains only ";"

      2) src/main/java/org/apache/openjpa/persistence/util/SourceCode.java#L812

      StringBuilder tmp = new StringBuilder(BLOCK_DELIMITER.start);
      

      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

              new RuntimeException("TradeJPADirect:resetTrade - not implemented in JPA mode");
      
      

      Exception is created, but not thrown.
      Same:

      4) openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/BaseKernelTest.java#L115-L118

                      // 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));
      

      props[i].startsWith("openjpa.") is checked twice.
      Same:

      5) openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/NameValidator.java#L30

      if(obj.getName().equals("") || obj.getName() == null)
      

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

      6) openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/VC.java#L115

                      (this.getVcId() == null &&
                      this.getVcId().equals(id.getVcId())
      

      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

              ClassMapping cm1 = (ClassMapping)((val1 instanceof Type) ? val1.getMetaData() :
                  val1.getMetaData());
      

      The parts of the ternary operator are same.
      Same:
      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
      Is it fallthrough? Or 'break' keyword is omitted?

      I hope this will be useful

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              AppChecker AppChecker
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: