Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    NullPointerException in Criterion.addCriteria

    SmartGWT Version: Smart GWT Pro Edition 4.0p (2013-12-18 nightly)

    We are migrating to SmartGWT Pro 4.0 and have encountered a NullPointerException in the com.smartgwt.client.data.Criterion class. In our case the this.getCriteria() call returns null, which causes the "this.getCriteria().length" call in the else block to throw a NullPointerException.

    Code:
        public void addCriteria(Criterion c) {
            String opString = this.getAttributeAsString("operator");
            if (opString != null && opString.equals(OperatorId.AND.getValue())) {
                appendToCriterionList(c);
            } else {
            	if (this.getAttributeAsObject("value") != null || this.getCriteria().length != 0) {
                    Criterion thisCopy = new Criterion(this);
                    JSOHelper.deleteAttributeIfExists(jsObj, "fieldName");
                    JSOHelper.deleteAttributeIfExists(jsObj, "value");
                    Criterion[] criteriaList = { thisCopy, c };
                    buildCriterionFromList(OperatorId.AND, criteriaList);                        
                } else {
                    buildCriterionFromList(OperatorId.AND, new Criterion[] {c});
                }
            }
        }
    
        public Criterion[] getCriteria() {
            JavaScriptObject[] jsCriteria = JSOHelper.getAttributeAsJavaScriptObjectArray(getJsObj(), "criteria");
            if (jsCriteria == null) return null;
            Criterion[] criteria = new Criterion[jsCriteria.length];
            
            for (int i = 0; i < jsCriteria.length; i++) {
                criteria[i] = Criterion.getOrCreateRef(jsCriteria[i]);
            }
            return criteria;
        }

    #2
    Unfortunately, we can't do much with this code, as it is presumably acting on some criteria put together elsewhere, and the fact that that criteria no longer has sub-criteria is presumably the issue.

    Also note, you're calling undocumented methods here, and those aren't supported so you should be careful about writing code that depends on them (this appears to be unnecessary in this particular piece of code).

    However, it seems as if your problem could be described without referring to this code - as just "some criteria no longer has the expected sub-criteria" - and so if you can show an instance where sub-criteria should be generated and aren't, and it's a framework issue, we can help with that.

    Comment


      #3
      That's not my code. That's SmartGWT code taken directly from com.smartgwt.client.data.Criterion in the nightly build, which was included to point out the bug.

      This isn't our exact code, but this will cause the NullPointerException to occur.
      Code:
      AdvancedCriteria advancedCriteria = new AdvancedCriteria();
      advancedCriteria.addCriteria("id", OperatorId.IS_NULL, (String)null);
      We were previously using a nightly build of SmartGWT 4.0 LGPL from July, and this exception did not occur with that. It did not include the this.getCriteria().length check.

      Comment


        #4
        Ah, the fact that this is a framework helper method explains the internal calls. Please clarify whether you are posting your own code or snippets of framework code in the future.

        We'll go ahead and fix the behavior for this sequence of calls, but note that once the fix is in place, you will end up with an "and" operator wrapped around your IS_NULL criterion. If you want AdvancedCriteria that don't involve an add, use just:

        Code:
        new AdvancedCriteria("id", OperatorId.IS_NULL, (String)null);
        .. instead.

        Comment


          #5
          You should see a fix for this in tonights nightly build of 4.0.

          Regards
          Isomorphic Software

          Comment

          Working...
          X