Foros de discusión

NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

Web Kowalski, modificado hace 12 años.

NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

New Member Mensajes: 3 Fecha de incorporación: 1/02/11 Mensajes recientes
hi liferayers!

I'm fairly new to Liferay. I have started portlet development with LR 6.0.6 and trying to migrate some portlets to LR 6.1. After some struggle with the migration of images from IG into the new DocumentLibrary (I like the unification of IG and DL emoticon ), I've run into a problem with AssetCategories, trying to store AssetCategories with some custom entities using AssetEntryLocalServiceUtil.updateEntry(...). This works fine with LR 6.0.6, but ends up with an NullPointerException in LR 6.1.

AssetEntryLocalServiceUtil.updateEntry(userId, groupId, CustomEntry.class.getName(), 
						entry.getPrimaryKey(), context.getAssetCategoryIds(), null);


causes an null pointer exception, because there is no AssetRenderFactory ( AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className) returns null)


14:32:25,704 ERROR [QuickNewsPortlet:405] error: 
java.lang.NullPointerException
	at com.liferay.portlet.asset.util.BaseAssetEntryValidator.validate(BaseAssetEntryValidator.java:105)
	at com.liferay.portlet.asset.util.BaseAssetEntryValidator.validate(BaseAssetEntryValidator.java:74)
	at com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.validate(AssetEntryLocalServiceImpl.java:815)
	at com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.updateEntry(AssetEntryLocalServiceImpl.java:572)
	at com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.updateEntry(AssetEntryLocalServiceImpl.java:548)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:112)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:59)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:108)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
	at $Proxy126.updateEntry(Unknown Source)


I've noticed, there was a null check in the previous version of BaseAssetEntryValidator.java (ln:105), which was removed.
Is there some property to set in portal-ext or do I need to write my own AssetRendererFactory and AssetRenderer for my custom entities?

any help would be appreciated.

(LR 6.1 GA1 / tomcat 7 / LR SDK 6.1 / win7 x64)
Antonino Rau, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
Hi,
have you doubled checked to have the right class in <asset-renderer-factory>XXXXXX</asset-renderer-factory> in liferay-portlet.xml for CustomEntry portlet plugin ?
Regards
Antonino Rau, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
.... looking at the source code it seems that
public AssetRendererFactory getAssetRendererFactoryByClassName(
String className) {

return _assetRenderFactoriesMapByClassName.get(className);
}

is returning null in AssetRendererFactoryRegistryImpl.
Web Kowalski, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

New Member Mensajes: 3 Fecha de incorporación: 1/02/11 Mensajes recientes
Tony Rad:
.... looking at the source code it seems that
public AssetRendererFactory getAssetRendererFactoryByClassName(
String className) {

return _assetRenderFactoriesMapByClassName.get(className);
}

is returning null in AssetRendererFactoryRegistryImpl.


Hi,

thank you for your answer.
Exactly, getAssetRendererFactoryByClassName returns null, which causes the null pointer in the validator class. In LR 6.0.6 there was no need to implement a custom asset renderer factory, it worked straight out of the box. Do I need to write a custom asset renderer and renderer factory and set it into liferay-portlet.xml <asset-renderer-factory> or is there a way to use some kind of default asset renderer, which will support custom entities? If so, can you give me some advise?

thank you
Tony Rad, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...) (Respuesta)

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
I don't know about LR6.0.6, in LR 6 it was needed and in LR 6.1 AssetRenderer seems still used in AssetRendererFactoryRegistryUtil:


	public static void register(AssetRendererFactory assetRendererFactory) {
		getAssetRendererFactoryRegistry().register(assetRendererFactory);
	}


moreover the Map returning null is an ConcurrentHashMap<String, AssetRendererFactory> AssetRendererFactory map.

You could give it a try implementing an AssetRendererFactory or simply writing a wrong value in <asset-renderer-factory>XXXXXX</asset-renderer-factory> and see what happens in the server log stack trace.
Tony Rad, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
Here is an example:


public class MyAssetRendererFactory extends BaseAssetRendererFactory { 
	
	public static final String CLASS_NAME = MyAsset.class.getName();
	
public static final String TYPE = "MyAsset";
public AssetRenderer getAssetRenderer(long classPK, int type)
           throws PortalException, SystemException {
           MyAsset asset = MyAssetLocalServiceUtil.getMyAsset(classPK);
           return new MyAssetRenderer(slogan);
       }
       public String getClassName() {
           return CLASS_NAME;
       }
       public String getType() {
           return TYPE;
       }
}


Regards
Web Kowalski, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

New Member Mensajes: 3 Fecha de incorporación: 1/02/11 Mensajes recientes
Hi,

I've now implemented a custom asset renderer and factory. The factory was correctly registered and I can store asset categories to my custom objects emoticon
Everthing works fine now.

Thank you very much for your assistance!

Regards
Tony Rad, modificado hace 12 años.

RE: NullPointerException using AssetEntryLocalServiceUtil.updateEntry(...)

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
glad to be helpful emoticon