Project

General

Profile

« Previous | Next » 

Revision 10047

Added by Matt Jones over 7 years ago

Fix issue in getDefaultReplicationPolicy.

Previously, under some circumstances, a ReplicationPolicy was created but was missing the optional replicationAllowed and numReplicas attributes. These are critical to the policy, so ensure they are set to sensible defaults even when property parsing errors and other issues might skip them. Added a test of this method, but I note that other methods in SystemMetadataFactory do not have unit tests and should be added if they are modified.

View differences:

SystemMetadataFactory.java
793 793
	 * than or equal to zero, no policy needs to be set, so return null.
794 794
	 * @return ReplicationPolicy, or null if no replication policy is needed
795 795
	 */
796
    private static ReplicationPolicy getDefaultReplicationPolicy() {
796
    protected static ReplicationPolicy getDefaultReplicationPolicy() {
797 797
        ReplicationPolicy rp = null;
798 798
        int numReplicas = -1;
799 799
        try {
800 800
            numReplicas = new Integer(PropertyService.getProperty("dataone.replicationpolicy.default.numreplicas"));
801 801
        } catch (NumberFormatException e) {
802
            // The property is not a valid integer, so return a null policy
803
            return null;
802
            // The property is not a valid integer, so set it to 0
803
            numReplicas = 0;
804 804
        } catch (PropertyNotFoundException e) {
805
            // The property is not found, so return a null policy
806
            return null;
805
            // The property is not found, so set it to 0
806
            numReplicas = 0;
807 807
        }
808 808
        
809
        rp = new ReplicationPolicy();
809 810
        if (numReplicas > 0) {
810
            rp = new ReplicationPolicy();
811 811
            rp.setReplicationAllowed(true);
812 812
            rp.setNumberReplicas(numReplicas);
813 813
            try {
......
832 832
            } catch (PropertyNotFoundException e) {
833 833
                // No blocked list found in properties, so just ignore it; no action needed
834 834
            }
835
        } else {
836
            rp.setReplicationAllowed(false);
837
            rp.setNumberReplicas(0);
835 838
        }
836 839
        return rp;
837 840
    }

Also available in: Unified diff