Program: 172160
Project: 172160
Buggy source:
@Override public String createDocument(String repositoryId,final Properties properties,String folderId,final ContentStream contentStream,final VersioningState versioningState,final List<String> policies,final Acl addAces,final Acl removeAces,ExtensionsData extension){
  checkRepositoryId(repositoryId);
  final CMISNodeInfo parentInfo=getOrCreateFolderInfo(folderId,"String_Node_Str");
  final String name=connector.getNameProperty(properties);
  final String objectTypeId=connector.getObjectTypeIdProperty(properties);
  final TypeDefinitionWrapper type=connector.getTypeForCreate(objectTypeId,BaseTypeId.CMIS_DOCUMENT);
  connector.checkChildObjectType(parentInfo,type.getTypeId());
  DocumentTypeDefinition docType=(DocumentTypeDefinition)type.getTypeDefinition(false);
  if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if (docType.isVersionable() && (versioningState == VersioningState.NONE)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if (!docType.isVersionable() && (versioningState != VersioningState.NONE)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  final File tempFile=copyToTempFile(contentStream);
  final Charset encoding=(tempFile == null ? null : getEncoding(tempFile,contentStream.getMimeType()));
  endReadOnlyTransaction();
  NodeRef newNodeRef=connector.getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>(){
    public NodeRef execute() throws Exception {
      try {
        NodeRef nodeRef=connector.getFileFolderService().create(parentInfo.getNodeRef(),name,type.getAlfrescoClass()).getNodeRef();
        connector.setProperties(nodeRef,type,properties,new String[]{PropertyIds.NAME,PropertyIds.OBJECT_TYPE_ID});
        connector.applyPolicies(nodeRef,type,policies);
        connector.applyACL(nodeRef,type,addAces,removeAces);
        if (contentStream != null) {
          ContentWriter writer=connector.getFileFolderService().getWriter(nodeRef);
          writer.setMimetype(contentStream.getMimeType());
          writer.setEncoding(encoding.name());
          writer.putContent(tempFile);
        }
        connector.applyVersioningState(nodeRef,versioningState);
        return nodeRef;
      }
 catch (      FileExistsException fee) {
        removeTempFile(tempFile);
        throw new CmisContentAlreadyExistsException("String_Node_Str",fee);
      }
catch (      IntegrityException ie) {
        removeTempFile(tempFile);
        throw new CmisConstraintException("String_Node_Str" + ie.getMessage(),ie);
      }
catch (      AccessDeniedException ade) {
        removeTempFile(tempFile);
        throw new CmisPermissionDeniedException("String_Node_Str",ade);
      }
    }
  }
,false,true);
  beginReadOnlyTransaction();
  removeTempFile(tempFile);
  return connector.createObjectId(newNodeRef);
}

Fixed version (ground truth):
@Override public String createDocument(String repositoryId,final Properties properties,String folderId,final ContentStream contentStream,final VersioningState versioningState,final List<String> policies,final Acl addAces,final Acl removeAces,ExtensionsData extension){
  checkRepositoryId(repositoryId);
  final CMISNodeInfo parentInfo=getOrCreateFolderInfo(folderId,"String_Node_Str");
  final String name=connector.getNameProperty(properties,null);
  final String objectTypeId=connector.getObjectTypeIdProperty(properties);
  final TypeDefinitionWrapper type=connector.getTypeForCreate(objectTypeId,BaseTypeId.CMIS_DOCUMENT);
  connector.checkChildObjectType(parentInfo,type.getTypeId());
  DocumentTypeDefinition docType=(DocumentTypeDefinition)type.getTypeDefinition(false);
  if ((docType.getContentStreamAllowed() == ContentStreamAllowed.NOTALLOWED) && (contentStream != null)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if ((docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) && (contentStream == null)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if (docType.isVersionable() && (versioningState == VersioningState.NONE)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  if (!docType.isVersionable() && (versioningState != VersioningState.NONE)) {
    throw new CmisConstraintException("String_Node_Str");
  }
  final File tempFile=copyToTempFile(contentStream);
  final Charset encoding=(tempFile == null ? null : getEncoding(tempFile,contentStream.getMimeType()));
  endReadOnlyTransaction();
  NodeRef newNodeRef=connector.getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>(){
    public NodeRef execute() throws Exception {
      try {
        NodeRef nodeRef=connector.getFileFolderService().create(parentInfo.getNodeRef(),name,type.getAlfrescoClass()).getNodeRef();
        connector.setProperties(nodeRef,type,properties,new String[]{PropertyIds.NAME,PropertyIds.OBJECT_TYPE_ID});
        connector.applyPolicies(nodeRef,type,policies);
        connector.applyACL(nodeRef,type,addAces,removeAces);
        if (contentStream != null) {
          ContentWriter writer=connector.getFileFolderService().getWriter(nodeRef);
          writer.setMimetype(contentStream.getMimeType());
          writer.setEncoding(encoding.name());
          writer.putContent(tempFile);
        }
        connector.applyVersioningState(nodeRef,versioningState);
        return nodeRef;
      }
 catch (      FileExistsException fee) {
        removeTempFile(tempFile);
        throw new CmisContentAlreadyExistsException("String_Node_Str",fee);
      }
catch (      IntegrityException ie) {
        removeTempFile(tempFile);
        throw new CmisConstraintException("String_Node_Str" + ie.getMessage(),ie);
      }
catch (      AccessDeniedException ade) {
        removeTempFile(tempFile);
        throw new CmisPermissionDeniedException("String_Node_Str",ade);
      }
    }
  }
,false,true);
  beginReadOnlyTransaction();
  removeTempFile(tempFile);
  return connector.createObjectId(newNodeRef);
}