Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java assertion getting mangled with Weblogic and Struts 2

I started using assertions in my Java EE 5 app and while the assert is working, the stack trace and messages are not. Here is my code:

  assert 4 == outputList.size() : "outputList is not size 4: " + outputList.size();

When I make the list size 3 it throws this:

<Error> <HTTP> <BEA-101020> <[weblogic.servlet.internal.WebAppServletContext@6ea53502 - appName: 'MyPortal', name: 'myportal', context-path: '/myportal'] Servlet failed with Exception
java.lang.NullPointerException
at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:610)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
>

It does not do a clean stack trace and does not have the assert message.

Any ideas?

like image 864
Scott Avatar asked May 18 '26 16:05

Scott


1 Answers

It is not the assert that throws that exception. You can use assert key word, but JVM normally ignores it, if you want to make JVM not to ignore it you must use java -enableassertions or java -ea.

So you must add this java parameter to your JAVA_OPTS.

like image 101
Amir Pashazadeh Avatar answered May 20 '26 06:05

Amir Pashazadeh