Menu

#494 strange NPE in VM_TypeReference on bean reflection

fixed
closed
runtime (64)
5
2012-09-21
2005-09-17
Anonymous
No

I set up to make Apache jetspeed run with jikesRVM +
classpath. I'm having (and am reporting both in
classpath and here) several JAAS/security and
classloading issues.

Once I arrived to a partly running setup, I was still
having an error in the bean loading of struts, giving a
NPE which originated at VM_TypeReference.

This patch solved it, and made struts run on my setup:

Index: classLoader/VM_TypeReference.java

RCS file:
/cvsroot/jikesrvm/rvm/src/vm/classLoader/VM_TypeReference.java,v
retrieving revision 1.20
diff -u -p -r1.20 VM_TypeReference.java
--- classLoader/VM_TypeReference.java 14 Jan 2005
05:44:31 -0000 1.20
+++ classLoader/VM_TypeReference.java 17 Sep 2005
07:42:44 -0000
@@ -572,7 +572,9 @@ public class VM_TypeReference
implements
public final boolean equals(Object other) {
if (other instanceof VM_TypeReference) {
VM_TypeReference that = (VM_TypeReference)other;
- return name == that.name &&
classloader.equals(that.classloader);
+ return name == that.name &&
+ (classloader == that.classloader ||
+ (classloader != null &&
classloader.equals(that.classloader)));
} else {
return false;
}

There are two possibilities here:
a) either VM_TypeReference.classloader != is a
representation invariant, and then it is somehow not
enforced
b) it is not, and then the patch is right, as we need
to check for it

Discussion

  • Santiago Gala

    Santiago Gala - 2005-09-17

    Logged In: YES
    user_id=178886

    I am Santiago Gala, BTW, just unable to undestand the state
    machine that sourceforge uses for login/session tracking :)

     
  • Santiago Gala

    Santiago Gala - 2005-09-21

    Logged In: YES
    user_id=178886

    Alternatively, if VM_TypeReference.classloader != null is a
    class invariant, preventing null references getting in can
    be achieved through this:

    Index: src/vm/classLoader/VM_TypeReference.java

    RCS file:
    /cvsroot/jikesrvm/rvm/src/vm/classLoader/VM_TypeReference.java,v
    retrieving revision 1.20
    diff -u -p -u -r1.20 VM_TypeReference.java
    --- src/vm/classLoader/VM_TypeReference.java 14 Jan 2005
    05:44:31 -0000 1.20
    +++ src/vm/classLoader/VM_TypeReference.java 21 Sep 2005
    08:14:18 -0000
    @@ -149,7 +149,7 @@ public class VM_TypeReference implements
    // classes must use the bootstrap classloader. Force
    that here so we don't // have to worry about it anywhere
    else in the VM.
    ClassLoader bootstrapCL =
    VM_BootstrapClassLoader.getBootstrapClassLoader();
    - if (cl != bootstrapCL) {
    + if (cl == null || cl != bootstrapCL) {
    if (tn.isClassDescriptor()) {
    if (tn.isBootstrapClassDescriptor()) {
    cl = bootstrapCL;
    @@ -168,6 +168,8 @@ public class VM_TypeReference implements
    }
    }
    // Next actually findOrCreate the type reference using
    the proper classloader.
    + if(cl == null)
    + cl = bootstrapCL;
    VM_TypeReference key = new VM_TypeReference(cl, tn);
    VM_TypeReference val =
    (VM_TypeReference)dictionary.get(key);
    if (val != null) return val;

    Requesting a "null" classLoader is a common idiom, and I was
    actually finding it in Struts code (Apache Commons
    Beanutils, IIRC).

     
  • Dave Grove

    Dave Grove - 2005-09-22

    Logged In: YES
    user_id=1215435

    classloader != null is supposed to be an invariant, so the
    second patch looks plausible. I'll give it a whirl and
    assuming no regressions it should get in later today. Thanks,

    --dave

     
  • Dave Grove

    Dave Grove - 2005-09-22

    Logged In: YES
    user_id=1215435

    committed slightly modified version of second patch to
    VM_TypeReference. I think it should fix the problem, if not
    let me know.

     

Log in to post a comment.