OpenJPA
  1. OpenJPA
  2. OPENJPA-251

org.apache.openjpa.enhance.Reflection.getDeclaredMethod() has undefined behavior, leading to VM-dependent crashes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.7
    • Fix Version/s: 1.0.2, 1.1.0
    • Component/s: jpa
    • Labels:
      None
    • Environment:
      Sun JDK 6.01

      Description

      Given

      public interface A

      { Object getId(); }

      @Entity
      public class B implements A {
      @Id
      public String getId()

      { return "foo"; }


      }

      B.class.getDeclaredMethods() will include both "public java.lang.String B.getId()" and "public java.lang.Object B.getId()". The order in which these two methods appear is NOT DEFINED! Because org.apache.openjpa.enhance.Reflection.getDeclaredMethod() returns the first matching method, and because that method might well be the abstract one retuning Object, OpenJPA will complain that it cannot persist an ID with a non-explicit strategy, and throw up.

      Class.getDeclaredMethod() (note singular, not plural) is defined to return the method with the most specific return type under these circumstances, and should therefore be used. Here's my implementation of Reflection.getDeclaredMethod:

      private static Method getDeclaredMethod(Class cls, String name, Class param)
      {
      Class[] params = param == null ? new Class[0] : new Class[]

      { param }

      ;
      try

      { return cls.getDeclaredMethod(name, params); }

      catch (Exception e)

      { return null; }

      }

      1. weirdness.zip
        2 kB
        Jonathan Feinberg

        Issue Links

          Activity

          Jonathan Feinberg created issue -
          Jonathan Feinberg made changes -
          Field Original Value New Value
          Attachment weirdness.zip [ 12359090 ]
          Craig L Russell made changes -
          Fix Version/s 1.0.0 [ 12312341 ]
          Affects Version/s 1.0.0 [ 12312341 ]
          Affects Version/s 0.9.7 [ 12312340 ]
          Marc Prud'hommeaux made changes -
          Fix Version/s 1.0.0 [ 12312341 ]
          Fix Version/s 1.0.1 [ 12312687 ]
          Albert Lee made changes -
          Fix Version/s 1.0.2 [ 12312846 ]
          Fix Version/s 1.0.1 [ 12312687 ]
          Patrick Linskey made changes -
          Link This issue is related to OPENJPA-329 [ OPENJPA-329 ]
          Patrick Linskey made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Patrick Linskey made changes -
          Fix Version/s 1.1.0 [ 12312344 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Jonathan Feinberg
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development