Changeset 29626

Show
Ignore:
Timestamp:
01/25/08 15:50:15 (10 months ago)
Author:
ogrisel
Message:

NXP-2008: Make CoreSession?.save/createDocument raise helpful ClientExceptions? instead of NullPointerExceptions?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.ecm.core/branches/1.4/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java

    r29127 r29626  
    4040import org.nuxeo.common.utils.IdUtils; 
    4141import org.nuxeo.common.utils.Path; 
    42 import org.nuxeo.common.utils.StringUtils; 
    4342import org.nuxeo.ecm.core.NXCore; 
    4443import org.nuxeo.ecm.core.api.event.CoreEvent; 
     
    594593        String typeName = docModel.getType(); 
    595594        DocumentRef parentRef = docModel.getParentRef(); 
    596         assert typeName != null; 
    597         assert parentRef != null; 
     595        if (typeName == null) { 
     596            throw new ClientException( 
     597                    String.format( 
     598                            "cannot create document '%s' with undefined type name", 
     599                            docModel.getTitle())); 
     600        } 
     601        if (parentRef == null) { 
     602            throw new ClientException( 
     603                    String.format( 
     604                            "cannot create document '%s' with undefined reference to parent document", 
     605                            docModel.getTitle())); 
     606        } 
    598607        try { 
    599608            Document folder = resolveReference(parentRef); 
     
    13051314            throws ClientException { 
    13061315        try { 
     1316            if (docModel.getRef() == null) { 
     1317                throw new ClientException(String.format( 
     1318                        "cannot save document '%s' with null reference: " 
     1319                                + "document has probably not yet been created " 
     1320                                + "in the repository with " 
     1321                                + "'CoreSession.createDocument(docModel)'", 
     1322                        docModel.getTitle())); 
     1323            } 
    13071324            Document doc = resolveReference(docModel.getRef()); 
    13081325            checkPermission(doc, WRITE); 
  • org.nuxeo.ecm.core/branches/1.4/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/DocumentResolver.java

    r28609 r29626  
    5555    public static Document resolveReference(Session session, DocumentRef docRef) 
    5656            throws DocumentException { 
     57        if (docRef == null) { 
     58            throw new DocumentException("Invalid reference (null)"); 
     59        } 
    5760        int type = docRef.type(); 
    5861        Object ref = docRef.reference();