Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: NullPointerException when calling generated -ServiceUtil method.
I have a class which implements an interface like this
After trying several times, I then give up this approach (in order to meetup with deadlines) and try using the standard ServiceUtil class...
I'm surprised I still get a NullPointerException at line 70 in my InsuranceProductService. That line corresponds with the point where getService() is supposed to be loaded by OSGI
I would ordinarily have preferred using the OSGI-injected local variable _insuranceServiceUtil (using the @Reference) instead of the Util class, but NullPointers still...I'm wondering why would this work inside a standard MVCActionCommand class, but not inside my component class. Whats he best and recomended way to handle this pls?Thanks
@Component(
immediate = true,
property = "javax.portlet.name=" + HmoInsurancePlansPortletKeys.INSURANCE_PLANS,
service = ConfigurationAction.class
)
public class InsuranceProductConfigurationAction
implements ConfigurationAction {
However whenever I try to retrieve an instance of my Service class (which was generated by ServiceBuilder), I get a vague NullPointerException. I use the standard way...@Referenceprivate InsuranceProductService _insuranceProductServiceAfter trying several times, I then give up this approach (in order to meetup with deadlines) and try using the standard ServiceUtil class...
InsuranceProductServiceUtil.addInsuranceProduct(name, titleMap,
descriptionMap, active, serviceContext);I'm surprised I still get a NullPointerException at line 70 in my InsuranceProductService. That line corresponds with the point where getService() is supposed to be loaded by OSGI
Line 70 return getService().addInsuranceProduct(
name, titleMap, descriptionMap, active, serviceContext);Here's the NullPointer...java.lang.NullPointerException
at com.tpl.pmedicshmo.kernel.service.InsuranceProductServiceUtil.addInsuranceProduct(InsuranceProductServiceUtil.java:70)
at com.tpl.pmedicshmo.insurance.plans.web.portlet.action.InsuranceProductConfigurationAction.addInsuranceProduct(InsuranceProductConfigurationAction.java:88)
at com.tpl.pmedicshmo.insurance.plans.web.portlet.action.InsuranceProductConfigurationAction.processAction(InsuranceProductConfigurationAction.java:58I would ordinarily have preferred using the OSGI-injected local variable _insuranceServiceUtil (using the @Reference) instead of the Util class, but NullPointers still...I'm wondering why would this work inside a standard MVCActionCommand class, but not inside my component class. Whats he best and recomended way to handle this pls?Thanks
Best is to use the @Reference. I'd rather recommend to give more information on what went wrong there.
Note: @Reference annotations only work within @Component annotated classes
Note: @Reference annotations only work within @Component annotated classes
Many Thanks Olaf. But my class is properly annotated with the @Component tag and the service class Is well specified. That's why I'm surprised...
Hi,
You try referencing your service like this once
You try referencing your service like this once
[code]private InsuranceProductService _insuranceProductService;
@Reference(unbind = "-")
protected void setInsuranceProductService(InsuranceProductService _insuranceProductService) {
_insuranceProductService= insuranceProductService;
}
Thanks Mohammed for reply. Ok now I find that from my component class (which happens to be a MVCActionCommand class) I can easily reference core portal service classes (eg UserService) like this...
then the NullPointers happen. For sake of clarity, my generate service classes live inside a different jar (and project) called pinsurance-api.jar (and this jar deploys safely to Liferay server without any errors). Compile dependencies are well defined in my project, referencing this jar. The bnd.bnd of pinsurance-api.jar clearly exports all necessary classes (like this)
and I don't get any unresolved dependencies when I deploy this project to Liferay server...!So what gives then?!!! Stuff's driving me crazy.
@Referenceprotected UserService _userService;and I can even make calls to service methods like getCurrentUser(). However the problem starts once I try to reference one of my own local services defined in service.xml. The moment I do something like this... |
| |
| |
| |
| |
|
Export-Package:\
com.tpl.pinsurance.api.exception,\
com.tpl.pinsurance.api.kernel.model,\
com.tpl.pinsurance.api.kernel.service,\and I don't get any unresolved dependencies when I deploy this project to Liferay server...!So what gives then?!!! Stuff's driving me crazy.
did you added in dependencies this service api in your build file ?
Ok guys, I've been fidgeting around with this all weekend & I'm still stuck with the NullPointer. Here's what I found though.My call to the
during runtime, since this jar name isn't explicitly mentioned in my build.gradle. Also, since this project is a local project, there's no way for me to add a dependency to it on the global gradle repo. The commented out dependency of course fails since it doesnt exist.I tried to include the jar as a resource inside my mvc-portlet's bnd.bnd like this...
But the NullPointer persists. I'm convinced my
then the nullpointer stops since this reference is reachable.
Question then is whats the best practices way to include my pmedicshmo-api.jar inside this web module, so that it's reachable during runtime?
Thanks everyone who's replied...David.
@Reference(unbind = "-")
protected void setInsurancePlanLocalService(InsurancePlanLocalService insurancePlanLocalService) {
_insurancePlanLocalService = insurancePlanLocalService;
}
protected InsurancePlanLocalService _insurancePlanLocalService;
is made from an mvc-portlet web module (inside an MVCRenderCommand). Here's my build.gradle filedependencies {
compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.clay", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.soy", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.service.tracker.collections", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "5.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.function", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.lang", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.string", version: "3.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "4.4.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "4.0.8"
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "org.osgi", name: "osgi.core", version: "6.0.0"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
compileOnly project(":hmo-configuration-admin-api")
[b][i] compileOnly project(":pmedicshmo-api")
//compileOnly group: "com.tpl", name: "com.tpl.pmedicshmo.api", version: "2.0.0"[/i][/b]
}
The 2 entries in bold caught my attention. The InsurancePlanLocalService which I tried to reference lives inside the separate project ":pmedicshmo-api"I'm suspecting the NullPointer happens because my dependency contains "compileOnly project" instead of "compileOnly group". It's possible OSGI fails to find the actual jar file (com.tpl.pmedicshmo.api-2.0.0.jar)during runtime, since this jar name isn't explicitly mentioned in my build.gradle. Also, since this project is a local project, there's no way for me to add a dependency to it on the global gradle repo. The commented out dependency of course fails since it doesnt exist.I tried to include the jar as a resource inside my mvc-portlet's bnd.bnd like this...
Bundle-Name: hmo-configuration-admin-web
Bundle-SymbolicName: com.tpl.pmedicshmo.configuration.admin.web
Bundle-Version: 2.0.0
-includeresource:\
@com.tpl.pmedicshmo.api-2.0.0.jarBut the NullPointer persists. I'm convinced my
pmedicshmo-api.jarcontaining the InsuranceLocalPlanService is somehow unreachable during runtime and hence the NullPointer. If I replace the reference with a core portal class like this @Reference(unbind = "-")
protected void setUserLocalService(UserLocalService userLocalService) {
_userLocalService = userLocalService;
}
protected UserLocalService _userLocalService; then the nullpointer stops since this reference is reachable.
Question then is whats the best practices way to include my pmedicshmo-api.jar inside this web module, so that it's reachable during runtime?
Thanks everyone who's replied...David.
you have to give api path properly in dependencies
in runtime means it has to be in the same projectfor example in dependencies:compile project(":modules:pmedicshmo:pmedicshmo-api")
it will be easy if you attach a pic where is this api and module exist
in runtime means it has to be in the same projectfor example in dependencies:compile project(":modules:pmedicshmo:pmedicshmo-api")
it will be easy if you attach a pic where is this api and module exist
Thanks Suresh for your reply. I have verified that all project paths are properly specified in my build.gradle. But just to be double sure, I have eliminated my compileProject directives and replaced them with compileGroup directives directly referencing the compiled jars like this...
I've replaced...
with
I've replaced...
compileOnly project(":pmedicshmo-impl-kernel")with
compileOnly group: "com.tpl.pmedicshmo", name: "com.tpl.pmedicshmo.kernel", version: "2.0.0"
Below is my complete build.gradle file...buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins", version: "4.0.23"
} repositories {
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}
}apply plugin: "com.liferay.plugin"dependencies {
compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.clay", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib.soy", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.service.tracker.collections", version: "4.0.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "5.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.function", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.lang", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.string", version: "3.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "4.4.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "4.0.8"
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "org.osgi", name: "osgi.core", version: "6.0.0"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
[b] compileOnly group: "com.tpl.pmedicshmo", name: "com.tpl.pmedicshmo.kernel", version: "2.0.0"[/b]
compileOnly project(":hmo-configuration-admin-api")
}repositories {
maven {
url "file://home/david/.m2/repository"
}
maven {
url "https://repository-cdn.liferay.com/nexus/content/groups/public"
}
}And here's the nullpointer exception I'm getting whenever I try to reference any servicebuilder entity inside the pmedicshmo-impl-kernel.jar...2019-09-24 08:52:32.752 ERROR [http-nio-8080-exec-8][PortletRequestDispatcherImpl:303] Unable to dispatch request: java.lang.NullPointerException
2019-09-24 08:52:32.754 ERROR [http-nio-8080-exec-8][PortletServlet:119] javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.NullPointerException
javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.NullPointerException
at com.liferay.portlet.internal.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:305)
at com.liferay.portlet.internal.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:123)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:578)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:594)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:160)
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:303)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:478)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:291)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.render(MVCPortlet.java:302)
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58)
at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:573)
at com.liferay.portlet.internal.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:670)
at com.liferay.portlet.internal.InvokerPortletImpl.render(InvokerPortletImpl.java:362)
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.lambda$render$0(MonitoringInvokerPortlet.java:280)
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet._render(MonitoringInvokerPortlet.java:383)
at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.render(MonitoringInvokerPortlet.java:278)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(Unknown Source)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:64)
at com.liferay.portal.servlet.DirectRequestDispatcherFactoryImpl$IndirectRequestDispatcher.include(DirectRequestDispatcherFactoryImpl.java:202)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:79)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portal.servlet.TransferHeadersHelperImpl$TransferHeadersRequestDispatcher.include(TransferHeadersHelperImpl.java:162)
at com.liferay.portlet.internal.PortletContainerImpl._render(PortletContainerImpl.java:918)
at com.liferay.portlet.internal.PortletContainerImpl.lambda$render$2(PortletContainerImpl.java:226)
at com.liferay.portlet.internal.PortletContainerImpl._preserveGroupIds(PortletContainerImpl.java:427)
at com.liferay.portlet.internal.PortletContainerImpl.render(PortletContainerImpl.java:214)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:147)
at com.liferay.portlet.RestrictPortletContainerWrapper.lambda$render$0(RestrictPortletContainerWrapper.java:131)
at com.liferay.portlet.RestrictPortletContainerWrapper._render(RestrictPortletContainerWrapper.java:192)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:129)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:215)
at com.liferay.portal.layoutconfiguration.util.velocity.TemplateProcessor.processMax(TemplateProcessor.java:149)
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:498)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:342)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
at org.apache.velocity.Template.merge(Template.java:328)
at org.apache.velocity.Template.merge(Template.java:235)
at com.liferay.portal.template.velocity.internal.VelocityTemplate.processTemplate(VelocityTemplate.java:109)
at com.liferay.portal.template.BaseTemplate.processTemplate(BaseTemplate.java:114)
at com.liferay.portal.layoutconfiguration.util.RuntimePageImpl.doProcessTemplate(RuntimePageImpl.java:445)
at com.liferay.portal.layoutconfiguration.util.RuntimePageImpl.doDispatch(RuntimePageImpl.java:359)
at com.liferay.portal.layoutconfiguration.util.RuntimePageImpl.getProcessedTemplate(RuntimePageImpl.java:110)
at com.liferay.portal.kernel.layoutconfiguration.util.RuntimePageUtil.getProcessedTemplate(RuntimePageUtil.java:37)
at com.liferay.application.list.taglib.display.context.logic.PanelAppContentHelper.writeContent(PanelAppContentHelper.java:86)
at org.apache.jsp.application_005fcontent.page_jsp._jspService(page_jsp.java:156)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:319)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:330)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portal.servlet.DirectServletPathRegisterDispatcher.include(DirectServletPathRegisterDispatcher.java:67)
at com.liferay.portal.servlet.DirectRequestDispatcherFactoryImpl$IndirectRequestDispatcher.include(DirectRequestDispatcherFactoryImpl.java:202)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:79)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.taglib.util.IncludeTag.includePage(IncludeTag.java:401)
at com.liferay.taglib.util.IncludeTag.include(IncludeTag.java:377)
at com.liferay.taglib.util.IncludeTag.doInclude(IncludeTag.java:220)
at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:89)
at org.apache.jsp.layout.view.control_005fpanel_jsp._jspService(control_005fpanel_jsp.java:125)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:319)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:330)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portal.servlet.TransferHeadersHelperImpl$TransferHeadersRequestDispatcher.include(TransferHeadersHelperImpl.java:162)
at com.liferay.portal.kernel.model.impl.BaseLayoutTypeControllerImpl.includeLayoutContent(BaseLayoutTypeControllerImpl.java:106)
at com.liferay.portal.model.impl.LayoutImpl.includeLayoutContent(LayoutImpl.java:885)
at com.liferay.portal.kernel.model.LayoutWrapper.includeLayoutContent(LayoutWrapper.java:1409)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:418)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:174)
at com.liferay.portal.struts.PortalRequestProcessor._process(PortalRequestProcessor.java:415)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:155)
at com.liferay.portal.internal.servlet.MainServlet.doGet(MainServlet.java:203)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at com.liferay.portal.internal.servlet.MainServlet.service(MainServlet.java:639)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:124)
at com.liferay.portal.servlet.filters.password.modified.PasswordModifiedFilter.processFilter(PasswordModifiedFilter.java:62)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.secure.BaseAuthFilter.processFilter(BaseAuthFilter.java:360)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.monitoring.internal.servlet.filter.MonitoringFilter.processFilter(MonitoringFilter.java:181)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at com.liferay.friendly.url.internal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:398)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.servlet.ServletAdapter.service(ServletAdapter.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:124)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:370)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.servlet.filters.password.modified.PasswordModifiedFilter.processFilter(PasswordModifiedFilter.java:62)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.secure.BaseAuthFilter.processFilter(BaseAuthFilter.java:360)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.etag.ETagFilter.processFilter(ETagFilter.java:89)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:266)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:88)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:266)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:147)
at com.liferay.portal.monitoring.internal.servlet.filter.MonitoringFilter.processFilter(MonitoringFilter.java:181)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:196)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:99)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:196)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:99)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)
at com.liferay.portal.servlet.filters.urlrewrite.UrlRewriteFilter.processFilter(UrlRewriteFilter.java:65)
at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:49)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:215)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:175)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:99)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:175)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:99)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:196)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:99)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.jasper.JasperException: java.lang.NullPointerException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:440)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:319)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:330)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portlet.internal.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:290)
... 220 more
Caused by: java.lang.NullPointerException
at org.apache.jsp.view_jsp._jspService(view_jsp:317)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
... 230 more
2019-09-24 08:52:32.762 ERROR [http-nio-8080-exec-8][render_portlet_jsp:131] null
java.lang.NullPointerException
at org.apache.jsp.view_jsp._jspService(view_jsp:317)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:319)
at com.liferay.portal.osgi.web.servlet.jsp.compiler.internal.JspServlet.service(JspServlet.java:330)
at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.include(RequestDispatcherAdaptor.java:48)
at com.liferay.portlet.internal.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:290)
at com.liferay.portlet.internal.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:123)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:578)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.include(MVCPortlet.java:594)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:160)
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:303)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:478)
Can't seem to figure out anything concrete from the stacktrace. Any help please guys?
David Ilechukwu:
The code that you provide above is just on the Java side. The stacktrace points to a problem within a JSP - that's where your NullpointerException originates.
Can't seem to figure out anything concrete from the stacktrace. Any help please guys?
One way to figure out what happens is to start this server in a debugger and set an exception breakpoint that's triggered by NullpointerException. If the debugger/IDE then is able to resolve the JSP as well, it will show you where in your JSP your exception occurs.
David do you find any solution?
We have same problem in liferay 7.3.1. Custom -LocalServiceUtil implementation in Java and JSP return NullPointerException.
We have same problem in liferay 7.3.1. Custom -LocalServiceUtil implementation in Java and JSP return NullPointerException.
Hany Bonyadi:
We have same problem in liferay 7.3.1. Custom -LocalServiceUtil implementation in Java and JSP return NullPointerException.
In OSGi times (e.g. since 7.0) you shouldn't use those LocalServiceUtil classes any more: They're effectively hiding your service dependency and might fail at runtime if the service is not available (just what you see). Instead, use proper @Reference annotations in your controller (e.g. Java) and forward those services to your JSP for use.
If a @Reference cannot be resolved, your whole bundle won't be started and you'd be forced to fix the root problem before you can ever run into runtime issues.
For me the <%@ page import="com.foo.EntityLocalServiceUtil" %> is working in Liferay 7.3.2 GA3
But if this is not the best way to do it "in OSGI Times", how can I forward the injected _entityLocalService to a JSP Page?
But if this is not the best way to do it "in OSGI Times", how can I forward the injected _entityLocalService to a JSP Page?
Andre Kreienbring:
Yes, it's working. But it'll likely also be working if you don't deploy the -service bundle - just generating a NullpointerException at runtime.
For me the <%@ page import="com.foo.EntityLocalServiceUtil" %> is working in Liferay 7.3.2 GA3
But if this is not the best way to do it "in OSGI Times", how can I forward the injected _entityLocalService to a JSP Page?
The proper way these days is to make everything explicitly available - e.g. by the portlet providing access to the JSP through a request attribute that the JSP can use to access anything in the backend.
Thank you for the hint with the request attribute. For others who may come across this:
Let's say you got your service builder entities injected into your module with
@Reference(unbind = "-")
protected void setEntityService(EntityLocalService entityLocalService) {
_entityLocalService = entityLocalService;
}
private EntityLocalService _entityLocalService ;
Then during in an action or render method of your module you can put selected objects into an request attribute
List<Entity> entities= _entityLocalService .getEntities(0, 5);
renderRequest.setAttribute("entities", entities);
And access the it from your JSP with (for example during the render phase)
<% List<Entity> entities= (List<Entity>) renderRequest.getAttribute("entities"); %>
This makes the classic approach of importing the whole service with
<%@ page import="[myServiceBuilder].service.EntityLocalServiceUtil" %>
unnecessary and even gives you more control over what is published to the JSP's in a request / response cycle. Also the businesslogic can be implemented in the Controller, which for me personally is much more convinient.
I haven't tried, but I think it's still possible to put the whole _entityLocalService in an attribute and access all methods from the JSP.
Can somebody tell about the memory and perfomance impacts about the different methods? I fear that passing around objects this way may be more costly then once importing things in the JSP pages.
Let's say you got your service builder entities injected into your module with
@Reference(unbind = "-")
protected void setEntityService(EntityLocalService entityLocalService) {
_entityLocalService = entityLocalService;
}
private EntityLocalService _entityLocalService ;
Then during in an action or render method of your module you can put selected objects into an request attribute
List<Entity> entities= _entityLocalService .getEntities(0, 5);
renderRequest.setAttribute("entities", entities);
And access the it from your JSP with (for example during the render phase)
<% List<Entity> entities= (List<Entity>) renderRequest.getAttribute("entities"); %>
This makes the classic approach of importing the whole service with
<%@ page import="[myServiceBuilder].service.EntityLocalServiceUtil" %>
unnecessary and even gives you more control over what is published to the JSP's in a request / response cycle. Also the businesslogic can be implemented in the Controller, which for me personally is much more convinient.
I haven't tried, but I think it's still possible to put the whole _entityLocalService in an attribute and access all methods from the JSP.
Can somebody tell about the memory and perfomance impacts about the different methods? I fear that passing around objects this way may be more costly then once importing things in the JSP pages.
David Ilechukwu:
However whenever I try to retrieve an instance of my Service class (which was generated by ServiceBuilder), I get a vague NullPointerException. I use the standard way...@Referenceprivate InsuranceProductService _insuranceProductService
After trying several times, I then give up this approach (in order to meetup with deadlines) and try using the standard ServiceUtil class... InsuranceProductServiceUtil.addInsuranceProduct(name, titleMap, descriptionMap, active, serviceContext);
I'm surprised I still get a NullPointerException at line 70 in my InsuranceProductService. That line corresponds with the point where getService() is supposed to be loaded by OSGILine 70 return getService().addInsuranceProduct( name, titleMap, descriptionMap, active, serviceContext);
This means that your InsuranceProductLocalService is not actually starting. Because it isn't starting, it can't be injected via @Reference annotation. And because it isn't starting, the InsuranceProductLocalServiceUtil's getService() method, which uses a ServiceTracker to find the currently available service, is returning null and that leads to your NPE.
It is precisely that issue with all of the LocalServiceUtil classes which is why they should be considered deprecated and not used. You have no visibility over whether the service is actually available and no time to make changes if it isn't, you just get stuck with the unchecked NPE exception.
What you need to do is learn how to use the gogo shell. Use commands like "lb", "scr:list" and "scr:info" to track down your service and see what is preventing it from starting. Resolve that issue and these other code pieces will just work.