Program: 172090
Project: 172090
Buggy source:
/** 
 * Open the file - Repo Specific implementation 
 */
public NetworkFile openFile(SrvSession session,TreeConnection tree,NodeRef rootNode,String path,OpenFileMode mode,boolean truncate) throws IOException {
  ContentContext ctx=(ContentContext)tree.getContext();
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + path + "String_Node_Str"+ mode);
  }
  try {
    String name=path;
    if (session.isPseudoFilesEnabled() && ctx.isPseudoFilesEnabled()) {
      String[] paths=FileName.splitPath(name);
      NodeRef dirNodeRef=getNodeForPath(rootNode,paths[0]);
      if (ctx.getPseudoFileOverlay().isPseudoFile(dirNodeRef,paths[1])) {
        PseudoFile pfile=ctx.getPseudoFileOverlay().getPseudoFile(dirNodeRef,paths[1]);
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + pfile);
        }
        return pfile.getFile(path);
      }
    }
    NodeRef nodeRef=getNodeForPath(rootNode,path);
    boolean readOnly=false;
switch (mode) {
case READ_ONLY:
case ATTRIBUTES_ONLY:
      if (permissionService.hasPermission(nodeRef,PermissionService.READ) == AccessStatus.DENIED) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + path);
        }
        throw new AccessDeniedException("String_Node_Str" + path);
      }
    readOnly=true;
  break;
case READ_WRITE:
case WRITE_ONLY:
if (permissionService.hasPermission(nodeRef,PermissionService.WRITE) == AccessStatus.DENIED) {
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + path);
  }
  throw new AccessDeniedException("String_Node_Str" + path);
}
lockService.checkForLock(nodeRef);
readOnly=false;
break;
case DELETE:
lockService.checkForLock(nodeRef);
}
NodeRef linkRef=(NodeRef)nodeService.getProperty(nodeRef,ContentModel.PROP_LINK_DESTINATION);
NetworkFile netFile=null;
if (linkRef == null) {
FileInfo fileInfo=cifsHelper.getFileInformation(nodeRef,"String_Node_Str",false,false);
if (fileInfo.isDirectory()) {
logger.debug("String_Node_Str");
netFile=new AlfrescoFolder(path,fileInfo,readOnly);
}
 else {
switch (mode) {
case READ_ONLY:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case READ_WRITE:
{
logger.debug("String_Node_Str");
File file=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
if (!truncate) {
ContentReader reader=contentService.getReader(nodeRef,ContentModel.PROP_CONTENT);
if (reader != null) {
reader.getContent(file);
}
}
netFile=new TempNetworkFile(file,name);
if (truncate) {
netFile.truncateFile(0);
}
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + name + "String_Node_Str"+ nodeRef+ "String_Node_Str"+ netFile);
}
netFile.setGrantedAccess(NetworkFile.READWRITE);
}
break;
case ATTRIBUTES_ONLY:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case DELETE:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case WRITE_ONLY:
{
logger.debug("String_Node_Str");
File file=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
netFile=new TempNetworkFile(file,name);
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + name + "String_Node_Str"+ nodeRef+ "String_Node_Str"+ netFile);
}
netFile.setGrantedAccess(NetworkFile.READWRITE);
}
}
}
}
 else {
String srvName=null;
SMBServer cifsServer=(SMBServer)session.getServer().getConfiguration().findServer("String_Node_Str");
if (cifsServer != null) {
srvName=cifsServer.getServerName();
}
 else {
srvName=InetAddress.getLocalHost().getHostName();
}
String pathl=getPathForNode(rootNode,linkRef);
path=pathl.replace(FileName.DOS_SEPERATOR,'/');
StringBuilder urlStr=new StringBuilder();
urlStr.append("String_Node_Str");
urlStr.append("String_Node_Str");
urlStr.append(srvName);
urlStr.append("String_Node_Str");
urlStr.append(tree.getSharedDevice().getName());
urlStr.append(pathl);
urlStr.append("String_Node_Str");
byte[] urlData=urlStr.toString().getBytes();
FileInfo fInfo=getCifsHelper().getFileInformation(nodeRef,false,isLockedFilesAsOffline);
fInfo.setFileSize(urlData.length);
netFile=new LinkMemoryNetworkFile(fInfo.getFileName(),urlData,fInfo,nodeRef);
netFile.setFullName(path);
}
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path + "String_Node_Str"+ netFile);
}
return netFile;
}
 catch (NodeLockedException nle) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path);
}
throw new AccessDeniedException("String_Node_Str" + path);
}
catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path);
}
throw new AccessDeniedException("String_Node_Str" + path);
}
catch (AlfrescoRuntimeException ex) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str",ex);
}
throw new IOException("String_Node_Str" + path,ex);
}
}

Fixed version (ground truth):
/** 
 * Open the file - Repo Specific implementation 
 */
public NetworkFile openFile(SrvSession session,TreeConnection tree,NodeRef rootNode,String path,OpenFileMode mode,boolean truncate) throws IOException {
  ContentContext ctx=(ContentContext)tree.getContext();
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + path + "String_Node_Str"+ mode);
  }
  try {
    String name=path;
    if (session.isPseudoFilesEnabled() && ctx.isPseudoFilesEnabled()) {
      String[] paths=FileName.splitPath(name);
      NodeRef dirNodeRef=getNodeForPath(rootNode,paths[0]);
      if (ctx.getPseudoFileOverlay().isPseudoFile(dirNodeRef,paths[1])) {
        PseudoFile pfile=ctx.getPseudoFileOverlay().getPseudoFile(dirNodeRef,paths[1]);
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + pfile);
        }
        return pfile.getFile(path);
      }
    }
    NodeRef nodeRef=getNodeForPath(rootNode,path);
    boolean readOnly=false;
switch (mode) {
case READ_ONLY:
case ATTRIBUTES_ONLY:
      if (permissionService.hasPermission(nodeRef,PermissionService.READ) == AccessStatus.DENIED) {
        if (logger.isDebugEnabled()) {
          logger.debug("String_Node_Str" + path);
        }
        throw new AccessDeniedException("String_Node_Str" + path);
      }
    readOnly=true;
  break;
case READ_WRITE:
case WRITE_ONLY:
if (permissionService.hasPermission(nodeRef,PermissionService.WRITE) == AccessStatus.DENIED) {
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + path);
  }
  throw new AccessDeniedException("String_Node_Str" + path);
}
lockService.checkForLock(nodeRef);
readOnly=false;
break;
case DELETE:
lockService.checkForLock(nodeRef);
}
NodeRef linkRef=(NodeRef)nodeService.getProperty(nodeRef,ContentModel.PROP_LINK_DESTINATION);
NetworkFile netFile=null;
if (linkRef == null) {
FileInfo fileInfo=cifsHelper.getFileInformation(nodeRef,"String_Node_Str",false,false);
if (fileInfo.isDirectory()) {
logger.debug("String_Node_Str");
netFile=new AlfrescoFolder(path,fileInfo,readOnly);
}
 else {
switch (mode) {
case READ_ONLY:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case READ_WRITE:
{
logger.debug("String_Node_Str");
File file=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
if (!truncate) {
ContentReader reader=contentService.getReader(nodeRef,ContentModel.PROP_CONTENT);
if (reader != null) {
reader.getContent(file);
}
}
netFile=new TempNetworkFile(file,name);
netFile.setGrantedAccess(NetworkFile.READWRITE);
if (truncate) {
netFile.truncateFile(0);
}
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + name + "String_Node_Str"+ nodeRef+ "String_Node_Str"+ netFile);
}
}
break;
case ATTRIBUTES_ONLY:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case DELETE:
logger.debug("String_Node_Str");
netFile=ContentNetworkFile.createFile(nodeService,contentService,mimetypeService,getCifsHelper(),nodeRef,path,true,session);
netFile.setGrantedAccess(NetworkFile.READONLY);
break;
case WRITE_ONLY:
{
logger.debug("String_Node_Str");
File file=TempFileProvider.createTempFile("String_Node_Str","String_Node_Str");
netFile=new TempNetworkFile(file,name);
netFile.setGrantedAccess(NetworkFile.READWRITE);
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + name + "String_Node_Str"+ nodeRef+ "String_Node_Str"+ netFile);
}
}
}
}
}
 else {
String srvName=null;
SMBServer cifsServer=(SMBServer)session.getServer().getConfiguration().findServer("String_Node_Str");
if (cifsServer != null) {
srvName=cifsServer.getServerName();
}
 else {
srvName=InetAddress.getLocalHost().getHostName();
}
String pathl=getPathForNode(rootNode,linkRef);
path=pathl.replace(FileName.DOS_SEPERATOR,'/');
StringBuilder urlStr=new StringBuilder();
urlStr.append("String_Node_Str");
urlStr.append("String_Node_Str");
urlStr.append(srvName);
urlStr.append("String_Node_Str");
urlStr.append(tree.getSharedDevice().getName());
urlStr.append(pathl);
urlStr.append("String_Node_Str");
byte[] urlData=urlStr.toString().getBytes();
FileInfo fInfo=getCifsHelper().getFileInformation(nodeRef,false,isLockedFilesAsOffline);
fInfo.setFileSize(urlData.length);
netFile=new LinkMemoryNetworkFile(fInfo.getFileName(),urlData,fInfo,nodeRef);
netFile.setFullName(path);
}
if (netFile != null) {
long id=DefaultTypeConverter.INSTANCE.convert(Long.class,nodeService.getProperty(nodeRef,ContentModel.PROP_NODE_DBID));
netFile.setFileId((int)(id & 0xFFFFFFFFL));
}
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path + "String_Node_Str"+ netFile);
}
return netFile;
}
 catch (NodeLockedException nle) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path);
}
throw new AccessDeniedException("String_Node_Str" + path);
}
catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str" + path);
}
throw new AccessDeniedException("String_Node_Str" + path);
}
catch (AlfrescoRuntimeException ex) {
if (logger.isDebugEnabled()) {
logger.debug("String_Node_Str",ex);
}
throw new IOException("String_Node_Str" + path,ex);
}
}