Announcement

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

    Problem with internal Java representation of SimpleCriterion

    Hi Isomorphic,

    I have a use case where I gather Criterion-Objects in a ArrayList<Criterion>.

    Until now, I fed only SetCriterion to it and converted with:
    Code:
    return new AdvancedCriteria(DefaultOperators.Or, additionalOrCrit.toArray(new SetCriterion[additionalOrCrit.size()])).asCriterion();
    No I realized that I don't need a SetCriterion if the Set consists only of 1 item. So I switched to SimpleCriterion for this.
    This does not work, and I assume this is because of the internal representation of the SimpleCriterion.
    While the SetCriterion is a JavaObject, the SimpleCriterion is a String, see screenshot of Eclipse debug mode.

    This leads to this exception for the return statement:
    Code:
    === 2014-07-04 15:38:47,876 [ec-5] WARN  RequestContext - dsRequest.execute() failed: 
    java.lang.ArrayStoreException
    	at java.lang.System.arraycopy(Native Method)
    	at java.util.ArrayList.toArray(Unknown Source)
    	at com.lmscompany.lms.server.util.Criteria.getCreatedByLegalEntityCriterion(Criteria.java:128)
    	at com.lmscompany.lms.server.worker.T_CAMPAIGN.fetchOwnAndOtherLECampaigns(T_CAMPAIGN.java:25)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:975)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:416)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
    	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2549)
    	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:215)
    	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:172)
    The whole method is:
    Code:
    public static Criterion getCreatedByLegalEntityCriterion(DSRequest dsRequest, TreeDirection treeDirection) throws Exception {
    	HashMap<String, HashSet<Long>> legalEntityStructure = User.getLegalEntityStructure(dsRequest, treeDirection);
    	if (legalEntityStructure == null)
    		return null;
    	ArrayList<Criterion> additionalOrCrit = new ArrayList<Criterion>();
    
    	for (LegalEntityType legalEntityType : LegalEntityType.values()) {
    		if (getEqualsOrSetCriterion(legalEntityStructure, legalEntityType) != null)
    			additionalOrCrit.add(getEqualsOrSetCriterion(legalEntityStructure, legalEntityType));
    	}
    	if (additionalOrCrit.size() >= 2)
    		return new AdvancedCriteria(DefaultOperators.Or, additionalOrCrit.toArray(new SetCriterion[additionalOrCrit.size()])).asCriterion();
    	if (additionalOrCrit.size() == 1)
    		return additionalOrCrit.get(0);
    	else
    		return null;
    }
    As this takes basically takes a some HashSet<Long> as only inputs, it is easy to reproduce, even without the the called methods.

    I'm using v9.1p_2014-06-29.

    Best regards,
    Blama
    Attached Files
    Last edited by Blama; 4 Jul 2014, 05:59. Reason: added version

    #2
    Hi Isomorphic,

    I worked around the 1st bug with this code (even though I still think it is a bug):
    Code:
    if (additionalOrCrit.size() >= 2) {
    	// return new AdvancedCriteria(DefaultOperators.Or,
    	// additionalOrCrit.toArray(new SetCriterion[additionalOrCrit.size()])).asCriterion();
    	AdvancedCriteria ac = AdvancedCriteria.fromCollections(additionalOrCrit, [B]DefaultOperators.Or.getID()[/B]);
    	Criterion c = ac.asCriterion();
    	return c;
    }
    This leads to a really bad bug. The AdvancedCriteria is an "AND"-Criteria, while it should be "OR". See screenshot.

    Best regards,
    Blama
    Attached Files

    Comment


      #3
      We see the issue noted in your second post and we'll fix it.

      We can't really follow your description of what you think is happening with the first problem. It seems as if you are just seeing the overridden toString() implementation in the debugger and mistaking that for an internal use of a String representation, but nothing of the kind is going on in SimpleCriterion.java. If you think there's still an issue here, we'll need some runnable code to reproduce the problem.

      Comment


        #4
        Hi Isomorphic,

        thanks for fixing the 2nd bug.

        Originally posted by Isomorphic View Post
        It seems as if you are just seeing the overridden toString() implementation in the debugger and mistaking that for an internal use of a String representation
        Yes, I did that. If the SimpleCriterion is the same as the rest of the Criterion, is it possible to have that toString() for the others as well? It really helps debugging.

        Regarding a testcase for the 1st bug: I'll try to create one on Monday.

        Best regards,
        Blama

        Comment


          #5
          At the moment, we don't plan a comprehensive set of toString() overrides. An easy way to get a clear String representation of AdvancedCriteria is to use DataTools.prettyPrint() with the Collections representation of the criteria.

          Comment


            #6
            Hi Isomorphic,

            the 1st report was an error on my side.
            Code:
            WRONG:
            return new AdvancedCriteria(DefaultOperators.Or, additionalOrCrit.toArray(new [B]Set[/B]Criterion[additionalOrCrit.size()])).asCriterion();
            CORRECT:
            return new AdvancedCriteria(DefaultOperators.Or, additionalOrCrit.toArray(new Criterion[additionalOrCrit.size()])).asCriterion();
            For the case of one element, my helper class returns a SimpleCriterion and not a SetCriterion, hence the Array has to be more generic.

            Thank you for the pointer to DataTools.prettyPrint(). It really helps.

            Regarding the 2nd report:
            This is NOT fixed for me in v9.1p_2014-07-06. I don't know if you meant that you can reproduce or that you already fixed it.

            Best regards,
            Blama
            Last edited by Blama; 7 Jul 2014, 02:33.

            Comment


              #7
              The fix for the 2nd report will be in tomorrow's build, (July 08).

              Regards
              Isomorphic Software

              Comment


                #8
                Hi Isomorphic,

                the 2nd report is fixed for me now.
                The 1st report was invalid.

                So for me, this is closed now.

                Thank you & Best regards,
                Blama

                Comment

                Working...
                X