Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-2026

save* and create* Before Advisor throws ClassCastException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Should
    • Resolution: Fixed
    • Affects Version/s: OpenMRS 1.8.0, OpenMRS 1.9.0
    • Fix Version/s: OpenMRS 1.8.0, OpenMRS 1.9.0
    • Component/s: None
    • Labels:
      None
    • Complexity:
      Low

      Description

      I wrote a save method with the following signature: saveMyObject(String, Integer, Integer), in both the service and DAO layers. When trying to execute the save method, I got the following error:

      java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

      It is because org.openmrs.aop.RequiredDataAdvice is trying to cast the second argument (in my case an Integer) as a String because the save method is assumed to be intended to have this alternate format. There is no try/catch around this call, and there is really no need for it if this kind of save or create method should be allowed. Ben provided me with the attached (patch) solution, even though I also changed my code to addMyObject() so I could avoid the advisor.

        Attachments

          Activity

            People

            Assignee:
            dkayiwa Daniel Kayiwa
            Reporter:
            jeremy Jeremy Keiper [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: