Program: 113417
Project: 113417
Buggy source:
public static void setSysAttrValue(StorageManager sMan,VolumeManager vMan,FileAccessManager faMan,long parentId,FileMetadata file,String keyString,String value,AtomicDBUpdate update) throws UserException, DatabaseException {
  if (keyString.startsWith(POLICY_ATTR_PREFIX.toString() + "String_Node_Str")) {
    setPolicyValue(sMan,keyString,value,update);
    return;
  }
  SysAttrs key=null;
  try {
    key=SysAttrs.valueOf(keyString);
  }
 catch (  IllegalArgumentException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + keyString + "String_Node_Str");
  }
switch (key) {
case default_sp:
    if (!file.isDirectory())     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
  try {
    org.xtreemfs.pbrpc.generatedinterfaces.GlobalTypes.StripingPolicy sp=null;
    sp=Converter.jsonStringToStripingPolicy(value);
    if (file.getId() == 1 && sp == null)     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
    sMan.setDefaultStripingPolicy(file.getId(),sp,update);
  }
 catch (  JSONException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  ClassCastException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  NullPointerException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  IllegalArgumentException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
break;
case osel_policy:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
try {
short[] newPol=Converter.stringToShortArray(value);
sMan.getVolumeInfo().setOsdPolicy(newPol,update);
}
 catch (NumberFormatException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
case rsel_policy:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
try {
short[] newPol=Converter.stringToShortArray(value);
sMan.getVolumeInfo().setReplicaPolicy(newPol,update);
}
 catch (NumberFormatException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
case read_only:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
boolean readOnly=Boolean.valueOf(value);
if (!readOnly && file.getXLocList() != null && file.getXLocList().getReplicaCount() > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
if (file.getXLocList() != null) {
XLocList xLoc=file.getXLocList();
XLoc[] replicas=new XLoc[xLoc.getReplicaCount()];
for (int i=0; i < replicas.length; i++) replicas[i]=xLoc.getReplica(i);
replicas[0].setReplicationFlags(ReplicationFlags.setFullReplica(ReplicationFlags.setReplicaIsComplete(replicas[0].getReplicationFlags())));
XLocList newXLoc=sMan.createXLocList(replicas,readOnly ? ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY : ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,xLoc.getVersion() + 1);
file.setXLocList(newXLoc);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
}
file.setReadOnly(readOnly);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case snapshots:
if (!file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str");
int index=value.indexOf("String_Node_Str");
String command=null;
String name=null;
try {
command=value.substring(0,index);
name=value.substring(index + 1);
}
 catch (Exception exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
if (command.charAt(0) == 'c') vMan.createSnapshot(sMan.getVolumeInfo().getId(),name,parentId,file,command.equals("String_Node_Str"));
 else if (command.equals("String_Node_Str")) vMan.deleteSnapshot(sMan.getVolumeInfo().getId(),file,name);
 else throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
break;
case snapshots_enabled:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
boolean enable=Boolean.parseBoolean(value);
sMan.getVolumeInfo().setAllowSnaps(enable,update);
break;
case mark_replica_complete:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
XLocList xlocs=file.getXLocList();
XLoc[] xlocArray=new XLoc[xlocs.getReplicaCount()];
Iterator<XLoc> it=xlocs.iterator();
for (int i=0; it.hasNext(); i++) {
XLoc xloc=it.next();
if (value.equals(xloc.getOSD(0))) xloc.setReplicationFlags(ReplicationFlags.setReplicaIsComplete(xloc.getReplicationFlags()));
xlocArray[i]=xloc;
}
XLocList newXLocList=sMan.createXLocList(xlocArray,xlocs.getReplUpdatePolicy(),xlocs.getVersion());
file.setXLocList(newXLocList);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case acl:
index=value.indexOf("String_Node_Str");
try {
command=value.substring(0,index);
String params=value.substring(index + 1);
if (command.equals("String_Node_Str")) {
int index2=params.lastIndexOf(':');
String entity=params.substring(0,index2);
String rights=params.substring(index2 + 1);
Map<String,Object> entries=new HashMap<String,Object>();
entries.put(entity,rights);
faMan.updateACLEntries(sMan,file,parentId,entries,update);
}
 else if (command.equals("String_Node_Str")) {
List<Object> entries=new ArrayList<Object>(1);
entries.add(params);
faMan.removeACLEntries(sMan,file,parentId,entries,update);
}
 else throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + command);
}
 catch (MRCException e) {
Logging.logError(Logging.LEVEL_ERROR,null,e);
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL);
}
catch (Exception exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
break;
case set_repl_update_policy:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
xlocs=file.getXLocList();
xlocArray=new XLoc[xlocs.getReplicaCount()];
it=xlocs.iterator();
for (int i=0; it.hasNext(); i++) xlocArray[i]=it.next();
String replUpdatePolicy=xlocs.getReplUpdatePolicy();
if (!ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(value) && !ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(value) && !ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)&& !ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value)) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_WARA.equals(value)) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && xlocArray.length > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)) {
if (xlocs.getReplicaCount() > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE + "String_Node_Str"+ xlocs.getReplicaCount()+ "String_Node_Str");
}
if ((ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && (ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(value) || ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(value))) || (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value) && (ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(replUpdatePolicy) || ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(replUpdatePolicy)))) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
newXLocList=sMan.createXLocList(xlocArray,value,xlocs.getVersion() + 1);
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value)) {
newXLocList.getReplica(0).setReplicationFlags(ReplicationFlags.setFullReplica(ReplicationFlags.setReplicaIsComplete(newXLocList.getReplica(0).getReplicationFlags())));
file.setReadOnly(true);
}
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)) {
file.setReadOnly(false);
}
file.setXLocList(newXLocList);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case default_rp:
if (!file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
try {
ReplicationPolicy rp=null;
rp=Converter.jsonStringToReplicationPolicy(value);
if (rp.getFactor() == 1 && !ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)) {
throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
}
sMan.setDefaultReplicationPolicy(file.getId(),rp,update);
}
 catch (JSONException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (ClassCastException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (NullPointerException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (IllegalArgumentException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
default :
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + keyString + "String_Node_Str");
}
}

Fixed version (ground truth):
public static void setSysAttrValue(StorageManager sMan,VolumeManager vMan,FileAccessManager faMan,long parentId,FileMetadata file,String keyString,String value,AtomicDBUpdate update) throws UserException, DatabaseException {
  if (keyString.startsWith(POLICY_ATTR_PREFIX.toString() + "String_Node_Str")) {
    setPolicyValue(sMan,keyString,value,update);
    return;
  }
  SysAttrs key=null;
  try {
    key=SysAttrs.valueOf(keyString);
  }
 catch (  IllegalArgumentException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + keyString + "String_Node_Str");
  }
switch (key) {
case default_sp:
    if (!file.isDirectory())     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
  try {
    org.xtreemfs.pbrpc.generatedinterfaces.GlobalTypes.StripingPolicy sp=null;
    sp=Converter.jsonStringToStripingPolicy(value);
    if (file.getId() == 1 && sp == null)     throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
    sMan.setDefaultStripingPolicy(file.getId(),sp,update);
  }
 catch (  JSONException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  ClassCastException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  NullPointerException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
catch (  IllegalArgumentException exc) {
    throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
  }
break;
case osel_policy:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
try {
short[] newPol=Converter.stringToShortArray(value);
sMan.getVolumeInfo().setOsdPolicy(newPol,update);
}
 catch (NumberFormatException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
case rsel_policy:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
try {
short[] newPol=Converter.stringToShortArray(value);
sMan.getVolumeInfo().setReplicaPolicy(newPol,update);
}
 catch (NumberFormatException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
case read_only:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
boolean readOnly=Boolean.valueOf(value);
if (!readOnly && file.getXLocList() != null && file.getXLocList().getReplicaCount() > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
if (file.getXLocList() != null) {
XLocList xLoc=file.getXLocList();
XLoc[] replicas=new XLoc[xLoc.getReplicaCount()];
for (int i=0; i < replicas.length; i++) replicas[i]=xLoc.getReplica(i);
replicas[0].setReplicationFlags(ReplicationFlags.setFullReplica(ReplicationFlags.setReplicaIsComplete(replicas[0].getReplicationFlags())));
XLocList newXLoc=sMan.createXLocList(replicas,readOnly ? ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY : ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE,xLoc.getVersion() + 1);
file.setXLocList(newXLoc);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
}
file.setReadOnly(readOnly);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case snapshots:
if (!file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_ENOTDIR,"String_Node_Str");
int index=value.indexOf("String_Node_Str");
String command=null;
String name=null;
try {
command=value.substring(0,index);
name=value.substring(index + 1);
}
 catch (Exception exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
if (command.charAt(0) == 'c') vMan.createSnapshot(sMan.getVolumeInfo().getId(),name,parentId,file,command.equals("String_Node_Str"));
 else if (command.equals("String_Node_Str")) vMan.deleteSnapshot(sMan.getVolumeInfo().getId(),file,name);
 else throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
break;
case snapshots_enabled:
if (file.getId() != 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
boolean enable=Boolean.parseBoolean(value);
sMan.getVolumeInfo().setAllowSnaps(enable,update);
break;
case mark_replica_complete:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
XLocList xlocs=file.getXLocList();
XLoc[] xlocArray=new XLoc[xlocs.getReplicaCount()];
Iterator<XLoc> it=xlocs.iterator();
for (int i=0; it.hasNext(); i++) {
XLoc xloc=it.next();
if (value.equals(xloc.getOSD(0))) xloc.setReplicationFlags(ReplicationFlags.setReplicaIsComplete(xloc.getReplicationFlags()));
xlocArray[i]=xloc;
}
XLocList newXLocList=sMan.createXLocList(xlocArray,xlocs.getReplUpdatePolicy(),xlocs.getVersion());
file.setXLocList(newXLocList);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case acl:
index=value.indexOf("String_Node_Str");
try {
command=value.substring(0,index);
String params=value.substring(index + 1);
if (command.equals("String_Node_Str")) {
int index2=params.lastIndexOf(':');
String entity=params.substring(0,index2);
String rights=params.substring(index2 + 1);
Map<String,Object> entries=new HashMap<String,Object>();
entries.put(entity,rights);
faMan.updateACLEntries(sMan,file,parentId,entries,update);
}
 else if (command.equals("String_Node_Str")) {
List<Object> entries=new ArrayList<Object>(1);
entries.add(params);
faMan.removeACLEntries(sMan,file,parentId,entries,update);
}
 else throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + command);
}
 catch (MRCException e) {
Logging.logError(Logging.LEVEL_ERROR,null,e);
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL);
}
catch (Exception exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
break;
case set_repl_update_policy:
if (file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EISDIR,"String_Node_Str");
xlocs=file.getXLocList();
xlocArray=new XLoc[xlocs.getReplicaCount()];
it=xlocs.iterator();
for (int i=0; it.hasNext(); i++) xlocArray[i]=it.next();
String replUpdatePolicy=xlocs.getReplUpdatePolicy();
if (!ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(value) && !ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(value) && !ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)&& !ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value)) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_WARA.equals(value)) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && xlocArray.length > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)) {
if (xlocs.getReplicaCount() > 1) throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE + "String_Node_Str"+ xlocs.getReplicaCount()+ "String_Node_Str");
}
if ((ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && (ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(value) || ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(value))) || (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value) && (ReplicaUpdatePolicies.REPL_UPDATE_PC_WQRQ.equals(replUpdatePolicy) || ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE.equals(replUpdatePolicy)))) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str");
}
newXLocList=sMan.createXLocList(xlocArray,value,xlocs.getVersion() + 1);
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(value)) {
newXLocList.getReplica(0).setReplicationFlags(ReplicationFlags.setFullReplica(ReplicationFlags.setReplicaIsComplete(newXLocList.getReplica(0).getReplicationFlags())));
file.setReadOnly(true);
}
if (ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY.equals(replUpdatePolicy) && ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(value)) {
file.setReadOnly(false);
}
file.setXLocList(newXLocList);
sMan.setMetadata(file,FileMetadata.RC_METADATA,update);
break;
case default_rp:
if (!file.isDirectory()) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
try {
ReplicationPolicy rp=null;
rp=Converter.jsonStringToReplicationPolicy(value);
if (rp.getFactor() == 1 && !ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE.equals(rp.getName())) {
throw new UserException(POSIXErrno.POSIX_ERROR_EPERM,"String_Node_Str");
}
sMan.setDefaultReplicationPolicy(file.getId(),rp,update);
}
 catch (JSONException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (ClassCastException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (NullPointerException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
catch (IllegalArgumentException exc) {
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + value);
}
break;
default :
throw new UserException(POSIXErrno.POSIX_ERROR_EINVAL,"String_Node_Str" + keyString + "String_Node_Str");
}
}