Announcement

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

    Class cast exception with Criterion class after rolling to new verion

    SmartGWT Version: v11.0p_2016-09-27/LGPL Development Only
    Browser: IE11
    Not a Server issue

    We just tried upgrading from a 5.0p build to 6.0p and started getting an exception in some of our code that was working with the older build. The code is below, but basically it attempts to get the criteria from a ListGrid and then determine if a Record object matches that criteria before adding the new record. The code snippet looks like (this code is in a class derived from ListGrid):

    Code:
    Criteria criteria = getCriteria();
    Criterion c = new Criterion();
    try {
        // HACK-POG: We are getting some strange cast exceptions on this addCriteria call so protecting against them
        c.addCriteria(criteria);
        if (dataSource.evaluateCriterion(entry.getRecord(), c)) {
            addRecords.add(entry.getRecord());
        }
        else {
            logger.finer("PMTableListGrid-" + gridId + ": Record " + recordId + " does not match criteria, ignoring add/update");
        }
    } catch (Throwable caught) {
        logger.log(Level.WARNING, "PMTableListGrid-" + gridId + ": Record " + recordId + " unexpected error evaluating criteria:\n" +
        "c.isAdvanced(): " + criteria.isAdvanced() + ", c instanceof AdvancedCriteria: " + (criteria instanceof AdvancedCriteria) +
        "\n" + JSON.encode(criteria.getJsObj()), caught);
        addRecords.add(entry.getRecord());
    }
    The code exceptions on the line "c.addCriteria(criteria).

    It appears to be dying in the addCriteria class in the last line of code where it tries to cast the incoming parameter to an AdvancedCriteria object:

    Code:
    public void addCriteria(Criteria c) {
        if (!c.isAdvanced() && !(c instanceof AdvancedCriteria)) {
            addCriteria(c.asAdvancedCriteria());
        } else {
            addCriteria((AdvancedCriteria)c);
        }
    }
    The log out from the exception looks like:

    Code:
    clientHost: 15.86.204.43, clientUser: PC-DEMO-LATEST\Unicorn, PMTableListGrid-jvJobsListGrid: Record a5a26e5ec21c4d9b807572b9b6a1e8c7 unexpected error evaluating criteria:
    c.isAdvanced(): true, c instanceof AdvancedCriteria: false
    {
        "operator":"and",
        "criteria":[
            {
                "operator":"and",
                "criteria":[
                    {
                        "fieldName":"job_status",
                        "operator":"iNotEqual",
                        "value":"Completed"
                    },
                    {
                        "fieldName":"job_status",
                        "operator":"iNotEqual",
                        "value":"Aborted"
                    }
                ]
            },
            {
                "fieldName":"job_deleting",
                "operator":"iEquals",
                "value":"false"
            }
        ],
        "_constructor":"AdvancedCriteria"
    }
    <log4j:throwable><![CDATA[java.lang.ClassCastException
     at Unknown.fillInStackTrace(Throwable.java:116)
     at Unknown.Throwable(Throwable.java:55)
     at Unknown.Exception(Exception.java:25)
     at Unknown.RuntimeException(RuntimeException.java:25)
     at Unknown.ClassCastException(ClassCastException.java:23)
     at Unknown.dynamicCast(Cast.java:59)
     at Unknown.addCriteria_1(Criterion.java:482)
     at Unknown.run_69(PMTableListGrid.java:754)
     at Unknown.fire_3(Timer.java:135)
     at Unknown.anonymous(Timer.java:139)
     at Unknown.apply_0(Impl.java:247)
     at Unknown.entry0(Impl.java:299)
     at Unknown.anonymous(Impl.java:72)
    ]]></log4j:throwable>
    Notice that the criteria object I got back from the grid shows that isAdvanced is true, but it is not an instance of an AdvancedCriteria object. This doesn't correct. The JSON representation seems to indicate that it is an AdvancedCriteria object.

    Help would be appreciated.
    Last edited by pgrever; 28 Sep 2016, 10:07.

    #2
    We were not able to reproduce your issue with our code. So, could you please post your test code so that we can test it and reproduce the issue?.

    Regards
    Isomorphic Software

    Comment


      #3
      We currently don't have test code for this. The code that builds up the criteria object that is assigned to the grid is quite complex and large. It is going to take a while before we can trim it down to a reasonable size to submit as running code. We'll post as soon as we can.

      Comment


        #4
        OK, the sample code is attached. The GWT log output looks like:

        Code:
        [INFO] [issues] - advCriteria.isAdvanced(): true
        [INFO] [issues] - advCriteria instanceof AdvancedCriteria: true
        [INFO] [issues] - criteria.isAdvanced(): true
        [INFO] [issues] - criteria instanceof AdvancedCriteria: false
        [INFO] [issues] - Exception: com.smartgwt.client.data.Criteria cannot be cast to com.smartgwt.client.data.AdvancedCriteria
        Note how the values are set correctly on the criteria used to set the criteria on the ListGrid, but when we query the grid for the criteria, the object that comes back is not set correctly any longer and that cases the add on the Criterion object to exception.
        Attached Files

        Comment


          #5
          We've made a change to address this issue. Please try the next nightly build, dated September 30.

          Regards
          Isomorphic Software

          Comment


            #6
            What was the exact old SGWT 5.0p version (including the date) that you upgraded from in which it worked?

            Comment


              #7
              Sorry, didn't see your latest messages until today. I'll try the update tomorrow. We were using:
              SmartGWT Version: v10.0p_2015-12-10/LGPL Development Only

              Comment


                #8
                Confirming that this is fixed. Thank you for all the help.

                Comment

                Working...
                X