History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QB-2421
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Unassigned
Reporter: AlSt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
QuickBuild

Changes REST and velocity template raises NullPointerException because a repository was changed

Created: 27/Apr/15 12:46 PM   Updated: 30/Apr/15 04:06 AM
Component/s: None
Affects Version/s: 5.1.40
Fix Version/s: 6.0.13

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
File Attachments: None
Image Attachments:

1. commitdate-null.PNG
(29 kb)


 Description  « Hide
We changed a repository to use another configuration path as dependency and now the change is shown with "Unknown Date" and "UNKNOWN" user (committer) with the message that the dependency to <old config name> has been removed.

When we use the rest request with /rest/changes/commits/build/<buildid> we get the error:
2015-04-27 14:29:19,040 [qtp1509221534-853415] ERROR com.pmease.quickbuild.rest.providers.GenericExceptionMapper - Error serving restful request.
    java.lang.NullPointerException
        at com.pmease.quickbuild.plugin.report.changes.rest.ChangesetMapper.handle(ChangesetMapper.java:47)
        at com.pmease.quickbuild.plugin.report.changes.rest.ChangesetMapper.handle(ChangesetMapper.java:18)
        at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:396)
        at com.pmease.quickbuild.plugin.report.engine.datastore.DbStore.query(DbStore.java:87)
        at com.pmease.quickbuild.plugin.report.engine.datastore.DbStore.query(DbStore.java:59)
        at com.pmease.quickbuild.plugin.report.changes.ChangesHelper.getBuildChangesets(ChangesHelper.java:283)
        at com.pmease.quickbuild.plugin.report.changes.rest.ChangesResource.getBuildChanges(ChangesResource.java:179)
        at sun.reflect.GeneratedMethodAccessor440.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:149)
        at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:67)
        at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:259)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
        at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:133)
        at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:71)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:990)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632)
        at com.pmease.quickbuild.rest.RestServlet.service(RestServlet.java:48)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

The relevant code line is: change.setDate(new Date(rs.getTimestamp("changesets.commitDate").getTime()));
It seems that the commitDate is null and so it raises a NPE.

Also the velocity template failed with a NPE:
2015-04-27 13:21:29,551 [pool-1-thread-17391] ERROR com.pmease.quickbuild.DefaultBuildEngine - Error processing build request.
    com.pmease.quickbuild.QuickbuildException: Failed to evaluate Velocity template.
        at com.pmease.quickbuild.util.ExceptionUtils.wrapException(ExceptionUtils.java:89)
        at com.pmease.quickbuild.util.VelocityUtils.evalTemplate(VelocityUtils.java:44)
        at com.pmease.quickbuild.plugin.notifier.email.EmailNotifier.notify(EmailNotifier.java:113)
        at com.pmease.quickbuild.DefaultBuildEngine.sendNotifications(DefaultBuildEngine.java:898)
        at com.pmease.quickbuild.DefaultBuildEngine.process(DefaultBuildEngine.java:414)
        at com.pmease.quickbuild.DefaultBuildEngine.access$000(DefaultBuildEngine.java:131)
        at com.pmease.quickbuild.DefaultBuildEngine$2.run(DefaultBuildEngine.java:1076)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getCommitters' in class com.pmease.quickbuild.model.Build threw exception java.lang.NullPointerException at custom_html_notification.vm[line 115, column 48]
        at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
        at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:567)
        at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:318)
        at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
        at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
        at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
        at org.apache.velocity.runtime.directive.Parse.render(Parse.java:260)
        at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
        at org.apache.velocity.runtime.RuntimeInstance.render(RuntimeInstance.java:1378)
        at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1314)
        at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1265)
        at org.apache.velocity.app.Velocity.evaluate(Velocity.java:180)
        at com.pmease.quickbuild.util.VelocityUtils.evalTemplate(VelocityUtils.java:41)
        ... 10 more
    Caused by: java.lang.NullPointerException

because there is something wrong with the changes.

I just took a look at the source of qb 6.0.10 and I think there is nothing different in the ChangesetMapper so this might also occur there.

 All   Comments   Work Log   Change History      Sort Order:
AlSt [27/Apr/15 02:59 PM]
we took a look inside one of the scm_activity h2.db files and there are indeed rows, where the commitdate is null.
seems like this is the cause for the NPE

Robin Shen [27/Apr/15 11:37 PM]
The NPE issue in RESTful API is a bug and we will get it fixed. However the error raised in custom_html_notification.vm is caused by your custom code, and to fixe it, you may need to check nullability of relevant objects to avoid calling getCommitters on it (most probably you are calling getCommitters on a repository that does not exist anymore).

AlSt [28/Apr/15 07:29 AM]
Thanks for looking into this.

We will check our template. We try to get the committers of a build not of a single repository. Also the Exception states that this exception occurs inside of getCommitters() of the class Build. Sadly the cause in the stacktrace is truncated. It may be unrelated to this issue but I think the problem is somewhere in the Build model class.

Another question: Is there any chance to get something like groovy templates as alternative to velocity templates? I mean the last velocity update was 2010 and we use groovy a lot so that would ease the template creation.

Thank you.

AlSt [28/Apr/15 08:44 AM]
I found a stacktrace which is not truncated from the template parsing:

2015-04-23 18:23:16,244 [pool-1-thread-5571] ERROR org.apache.velocity.runtime.directive.Parse - Exception rendering #parse(
tml_notification.vm) at velocity[line 1, column 1]
2015-04-23 18:23:16,250 [pool-1-thread-5571] ERROR com.pmease.quickbuild.DefaultBuildEngine - Error processing build request.
    com.pmease.quickbuild.QuickbuildException: Failed to evaluate Velocity template.
     at com.pmease.quickbuild.util.ExceptionUtils.wrapException(ExceptionUtils.java:89)
     at com.pmease.quickbuild.util.VelocityUtils.evalTemplate(VelocityUtils.java:44)
     at com.pmease.quickbuild.plugin.notifier.email.EmailNotifier.notify(EmailNotifier.java:113)
     at com.pmease.quickbuild.DefaultBuildEngine.sendNotifications(DefaultBuildEngine.java:898)
     at com.pmease.quickbuild.DefaultBuildEngine.process(DefaultBuildEngine.java:414)
     at com.pmease.quickbuild.DefaultBuildEngine.access$000(DefaultBuildEngine.java:131)
     at com.pmease.quickbuild.DefaultBuildEngine$2.run(DefaultBuildEngine.java:1076)
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
     at java.util.concurrent.FutureTask.run(FutureTask.java:262)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
     at java.lang.Thread.run(Thread.java:745)
    Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getCommitters' in class com.pmease.quickbuild.model.Build threw exception java.lang.NullPointerException at custom_html_notification.vm[line 115, column 48]
     at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)
     at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
     at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:567)
     at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:318)
     at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
     at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
     at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
     at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
     at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
     at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
     at org.apache.velocity.runtime.directive.Parse.render(Parse.java:260)
     at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
     at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
     at org.apache.velocity.runtime.RuntimeInstance.render(RuntimeInstance.java:1378)
     at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1314)
     at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1265)
     at org.apache.velocity.app.Velocity.evaluate(Velocity.java:180)
     at com.pmease.quickbuild.util.VelocityUtils.evalTemplate(VelocityUtils.java:41)
     ... 10 more
    Caused by: java.lang.NullPointerException
     at com.pmease.quickbuild.plugin.report.changes.rest.ChangesetMapper.handle(ChangesetMapper.java:47)
     at com.pmease.quickbuild.plugin.report.changes.rest.ChangesetMapper.handle(ChangesetMapper.java:18)
     at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:396)
     at com.pmease.quickbuild.plugin.report.engine.datastore.DbStore.query(DbStore.java:87)
     at com.pmease.quickbuild.plugin.report.engine.datastore.DbStore.query(DbStore.java:59)
     at com.pmease.quickbuild.plugin.report.changes.ChangesHelper.getBuildChangesets(ChangesHelper.java:283)
     at com.pmease.quickbuild.plugin.report.changes.generator.DefaultChangesRecorder.read(DefaultChangesRecorder.java:53)
     at com.pmease.quickbuild.ServerServiceImpl.readChanges(ServerServiceImpl.java:271)
     at com.pmease.quickbuild.model.Build.getChanges(Build.java:616)
     at com.pmease.quickbuild.model.Build.getCommitters(Build.java:750)
     at sun.reflect.GeneratedMethodAccessor755.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:606)
     at org.apache.velocity.runtime.parser.node.PropertyExecutor.execute(PropertyExecutor.java:142)
     at org.apache.velocity.util.introspection.UberspectImpl$VelGetterImpl.invoke(UberspectImpl.java:539)
     at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:198)
     ... 27 more

Here you can see it is the exact same problem.