Project

General

Profile

Revision 0f1cc6a3

ID0f1cc6a39ec62870c4ae5184445e1a4222c65adf
Parent 64688697
Child 25f9ee23, c5eb9820

Added by Andreas Kohlbecker over 1 year ago

ref #7702 avoiding NPE in TargetEntityStates when pervious state is null

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/TargetEntityStates.java
60 60
        return previousState != null;
61 61
    }
62 62

  
63
    /**
64
     * Compares the current state of the entity property (state being persisted) with the previous state
65
     * (state to be overwritten in the storage) and returns <code>true</code> in case there is a previous
66
     * state and the new state is different.
67
     *
68
     * @param propertyName
69
     * @return
70
     */
63 71
    public boolean propertyChanged(String propertyName){
64 72
        if(propertyNames == null){
65 73
            // usually during a save or delete operation
66 74
            return false;
67 75
        }
76
        if(!hasPreviousState()){
77
            // should be covered by propertyNames == null but this check seems to be nececary in rare situations
78
            // see the NPE stack strace in #7702 for an example
79
            return false;
80
        }
68 81
        int i = 0;
69 82
        for(String p : propertyNames){
70 83
            if(p.equals(propertyName)){
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/permission/voter/RegistrationVoter.java
53 53

  
54 54
            RegistrationStatus status;
55 55
            if(targetEntityStates.propertyChanged("status")){
56
                status = targetEntityStates.previousPropertyState("status", RegistrationStatus.class); 
56
                status = targetEntityStates.previousPropertyState("status", RegistrationStatus.class);
57 57
            } else {
58 58
                status = ((Registration)targetEntityStates.getEntity()).getStatus();
59
                
59

  
60 60
            }
61 61
            vr.isPropertyMatch = cdmAuthority.getProperty().contains(status.name());
62 62
            logger.debug("property is matching");

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)