cancel
Showing results for 
Search instead for 
Did you mean: 

Nullpointer exception when updating properties

glaenen
Champ in-the-making
Champ in-the-making
Hello, I'm trying to use alfresco opencmis extension to update properties in custom types and custom aspects.
And I'm getting nullpointer exceptions in 2 specific cases:

- When trying to update a property contained  by an aspect that was never set to that document before.
  So adding a property to the hashmap with an empty string when creating a file ( properties.put("mySmiley Tonguerop", "");  )
  enables me to update mySmiley Tonguerop without a problem, otherwise I get a nullpointer exception.

- When trying to update a property of a custom aspect applied to a document of a custom type.
  Updating properties contained by the type itself is no problem.
  Also when I apply this aspect to the default cmis:domunent there is no problem.
  Combining both the custom type and custom aspect and I get a nullpointer exception.

Either of the 2 cases above gives me:

Exception in thread "main" java.lang.NullPointerException
   at org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl.convertProperties(Unknown Source)
   at org.apache.chemistry.opencmis.client.runtime.AbstractCmisObject.updateProperties(AbstractCmisObject.java:314)
   at org.alfresco.cmis.client.impl.AlfrescoDocumentImpl.updateProperties(Unknown Source)
   at org.apache.chemistry.opencmis.client.runtime.AbstractCmisObject.updateProperties(AbstractCmisObject.java:277)
   at be.cmc.qp.JavaCMIS2.pathAndUpdateProperty(JavaCMIS2.java:314)
   at be.cmc.qp.JavaCMIS2.main(JavaCMIS2.java:51)

Is anybody else having the same issues? Or knows what is going wrong?
Hopefully my explanation is clear enough.

Thanks,

Glenn
8 REPLIES 8

fmui
Champ in-the-making
Champ in-the-making
Hi Glenn,

Are you using the latest version (alfresco-opencmis-extension-110204.jar), released last Friday?
You can't update properties of an aspect that is not applied to the object.

Cheers,

Florian

glaenen
Champ in-the-making
Champ in-the-making
Hello,

"Are you using the latest version (alfresco-opencmis-extension-110204.jar), released last Friday?"

Yes I use the latest version.

"You can't update properties of an aspect that is not applied to the object."

The aspect is applied to the object, but the properties in the aspect are not.
Meaning that I can see the aspect is on the object in the node browser, but the properties are not
shown because they aren't set.

example:

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "doc1");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:my:aspect");
properties.put("mySmiley Tonguerop1", "abcdef");
properties.put("mySmiley Tonguerop2", "");
Document doc = session.getRootFolder().createDocument(properties, null, null);

When I create a document as shown above I can edit both mySmiley Tonguerop1 and mySmiley Tonguerop2.
But when I don't add mySmiley Tonguerop2 in the hashmap (because I don't want to set its value at this point),
you get a nullpointer exception when you try to update mySmiley Tonguerop2 with alfDoc.updateProperties(properties);

Regards,

Glenn

fmui
Champ in-the-making
Champ in-the-making
Hi Glenn,

I have set up a test case that emulates what you are doing but I can't reproduce the problem. I don't see a NPE.
Also, createDocument and updateProperties are independent. Setting or not setting a property for createDocument shouldn't have an effect on updateProperties.

Would it be possible to share your aspect definition with me?

- Florian

glaenen
Champ in-the-making
Champ in-the-making
Hello,

This is the aspect I use. And below this you can find the code I use to create and then update one off the properties.
And the software version I user are:

alfresco-opencmis-extension-110204
chemistry-opencmis-client-impl-0.2.0-incubating-with-dependencies
alfresco-community-sdk-3.4.b
alfresco-community-3.4.b-installer-linux-x32

Thanks,

Glenn


<aspect name="qp:salesrep">
         <title>Sales Representative</title>
         <properties>
            <property name="qp:insideSalesRep">
               <title>Inside Sales Representative</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="qpSmiley SurprisedutsideSalesRep">
               <title>Outside Sales Representative</title>
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
         </properties>
      </aspect>



Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "doc1");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document,P:qp:salesrep");
properties.put("qp:insideSalesRep", "abcdef");
//properties.put("qpSmiley SurprisedutsideSalesRep", "");
Document doc = session.getRootFolder().createDocument(properties, null, null);


Document doc = (Document) session.getObjectByPath("/doc1");
AlfrescoDocument alfDoc = (AlfrescoDocument) doc;
if ( alfDoc.hasAspect("P:qp:salesrep")){
   System.out.println("aspect salesrep found");
   Map<String,String> properties = new HashMap<String, String>();
        properties.put("qpSmiley SurprisedutsideSalesRep", "test test test");
        alfDoc.updateProperties(properties);
   }

glaenen
Champ in-the-making
Champ in-the-making
And I just installed 3.4c and I got the same 2 problems.

Regards,

Glenn

glaenen
Champ in-the-making
Champ in-the-making
Hello,

I found the cause of the problem in AlfrescoObjectFactoryImpl @ line 141.
It tries to add the custom propertydefinition on the aspect P:sys:incomplete.
I currently bypassed this by adding "aspectTypes.remove(0);"
It would be better to make sure sys:incomplete in not in aspectTypes in the first place, but I don't know how to do that 🙂

I'll check if I can find the cause of the second nullpointer exception too.

Regards,

Glenn

glaenen
Champ in-the-making
Champ in-the-making
Hello,

The second nullpointer execption had the same cause as the first one.
I now changed the following @ ling 136 in AlfrescoObjectFactoryImpl

for (ObjectType aspectType : aspectTypes)
{
     PropertyDefinition<?> propDef = aspectType.getPropertyDefinitions().get(id);
                    if (propDef != null)
                    {
                        aspectPropertyDefinition.put(id, propDef);
                        break;
                    }
}

to

for (ObjectType aspectType : aspectTypes)
{
         if ( aspectType.getPropertyDefinitions() != null ){
               PropertyDefinition<?> propDef = aspectType.getPropertyDefinitions().get(id);
                        if (propDef != null)
                        {
                            aspectPropertyDefinition.put(id, propDef);
                            break;
                        }
          }
}


This solves both problems.

fmui
Champ in-the-making
Champ in-the-making
Now it makes sense!
The aspect sys:incomplete is automatically applied if a mandatory property value is not set. And it has no properties, which wasn't covered by the extension code yet.

I have uploaded a new revision of the extension. Please give it a try.


Thanks a lot!

Florian