LPS-48477 Add null check for parameters

Hi Shuyang,

This is the first part, the null check of parameters.

I am using Integer.MIN_VALUE instead of 0 we talked about before for default timeToLive value, since using 0 as default will cause exception while staring portal, I have no idea why this happened, and tried to fix it but fail.

You can easily reproduce it by make all the put in EhcachPortalCache do element.setTimeTolive(0).

See full error log below in case you are instreasted:

09:22:37,107 ERROR [localhost-startStop-1][PortalInstances:500] com.liferay.portal.kernel.events.ActionException: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
com.liferay.portal.kernel.events.ActionException: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	at com.liferay.portal.events.AddDefaultLayoutSetPrototypesAction.run(AddDefaultLayoutSetPrototypesAction.java:52)
	at com.liferay.portal.events.AddDefaultDataAction.run(AddDefaultDataAction.java:45)
	at com.liferay.portal.kernel.events.SimpleAction.processLifecycleEvent(SimpleAction.java:26)
	at com.liferay.portal.events.EventsProcessorUtil._process(EventsProcessorUtil.java:129)
	at com.liferay.portal.events.EventsProcessorUtil.process(EventsProcessorUtil.java:74)
	at com.liferay.portal.util.PortalInstances._initCompany(PortalInstances.java:494)
	at com.liferay.portal.util.PortalInstances.initCompany(PortalInstances.java:93)
	at com.liferay.portal.servlet.MainServlet.initCompanies(MainServlet.java:760)
	at com.liferay.portal.servlet.MainServlet.init(MainServlet.java:332)
	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:657)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1637)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:744)
Caused by: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.processException(BasePersistenceImpl.java:250)
	at com.liferay.portal.service.persistence.impl.ResourcePermissionPersistenceImpl.fetchByC_N_S_P_R(ResourcePermissionPersistenceImpl.java:3622)
	at com.liferay.portal.service.persistence.impl.ResourcePermissionPersistenceImpl.fetchByC_N_S_P_R(ResourcePermissionPersistenceImpl.java:3489)
	at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.doUpdateResourcePermission(ResourcePermissionLocalServiceImpl.java:1102)
	at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.updateResourcePermission(ResourcePermissionLocalServiceImpl.java:1281)
	at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.setResourcePermissions(ResourcePermissionLocalServiceImpl.java:1047)
	at sun.reflect.GeneratedMethodAccessor268.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:55)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)
	at com.sun.proxy.$Proxy22.setResourcePermissions(Unknown Source)
	at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addGroupPermissions(ResourceLocalServiceImpl.java:576)
	at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addGroupPermissions(ResourceLocalServiceImpl.java:566)
	at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addResources(ResourceLocalServiceImpl.java:869)
	at com.liferay.portal.service.impl.ResourceLocalServiceImpl.addResources(ResourceLocalServiceImpl.java:260)
	at sun.reflect.GeneratedMethodAccessor511.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:55)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)
	at com.sun.proxy.$Proxy18.addResources(Unknown Source)
	at com.liferay.portal.service.impl.LayoutLocalServiceImpl.addLayout(LayoutLocalServiceImpl.java:413)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
	at com.liferay.portal.service.impl.LayoutLocalServiceVirtualLayoutsAdvice.invoke(LayoutLocalServiceVirtualLayoutsAdvice.java:181)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.invoke(LayoutLocalServiceStagingAdvice.java:139)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:55)
	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)
	at com.sun.proxy.$Proxy118.addLayout(Unknown Source)
	at com.liferay.portal.service.LayoutLocalServiceUtil.addLayout(LayoutLocalServiceUtil.java:261)
	at com.liferay.portal.events.BaseDefaultLayoutPrototypesAction.addLayout(BaseDefaultLayoutPrototypesAction.java:65)
	at com.liferay.portal.events.AddDefaultLayoutSetPrototypesAction.addPublicSite(AddDefaultLayoutSetPrototypesAction.java:283)
	at com.liferay.portal.events.AddDefaultLayoutSetPrototypesAction.doRun(AddDefaultLayoutSetPrototypesAction.java:298)
	at com.liferay.portal.events.AddDefaultLayoutSetPrototypesAction.run(AddDefaultLayoutSetPrototypesAction.java:47)
	... 25 more
Caused by: com.liferay.portal.kernel.dao.orm.ORMException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	at com.liferay.portal.dao.orm.hibernate.ExceptionTranslator.translate(ExceptionTranslator.java:33)
	at com.liferay.portal.dao.orm.hibernate.QueryImpl.list(QueryImpl.java:125)
	at com.liferay.portal.dao.orm.hibernate.QueryImpl.list(QueryImpl.java:98)
	at com.liferay.portal.service.persistence.impl.ResourcePermissionPersistenceImpl.fetchByC_N_S_P_R(ResourcePermissionPersistenceImpl.java:3593)
	... 71 more
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:638)
	at java.util.ArrayList.get(ArrayList.java:414)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
	at com.liferay.portal.dao.orm.hibernate.QueryImpl.list(QueryImpl.java:113)
	... 73 more