My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 3666: Internal server error when publishing an edit
2 people starred this issue and may be notified of changes. Back to list
Status:  Released
Owner:  ----
Closed:  Nov 11


Sign in to add a comment
 
Reported by antonio....@wandisco.com, Nov 11, 2015
Affected Version: 2.11.4

What steps will reproduce the problem?
1. Install gerrit 2.11.4
2. create a new project WITHOUT the first commit
3. clone the project (there is no master branch)
4. commit something and push HEAD:refs/for/master
5. go to the UI and try to add a new file to the patchset you just pushed (using "edit", "add...", "save file", "close")
6. click on "Publish Edit" and get the Internal server error

What is the expected output? What do you see instead?
I see "Internal server error". I expect the change to be published even if there is no master branch.

Please provide any additional information below.

Looks like it's due to a small bug in the newly added onCommitReceived function. 

This is the log file:

[2015-11-11 11:41:34,374] INFO  com.google.gerrit.sshd.SshDaemon : Started Gerrit SSHD-CORE-0.14.0 on *:29418
[2015-11-11 11:41:34,379] INFO  org.eclipse.jetty.server.Server : jetty-9.2.9.v20150224
[2015-11-11 11:41:34,946] INFO  org.eclipse.jetty.server.handler.ContextHandler : Started o.e.j.s.ServletContextHandler@2722df44{/,file:/Users/antonio/tmp/gerrit2114/tmp/gerrit_3885722229358823659_app/g
errit_war/,AVAILABLE}
[2015-11-11 11:41:34,950] INFO  org.eclipse.jetty.server.ServerConnector : Started ServerConnector@5047fad1{HTTP/1.1}{0.0.0.0:8080}
[2015-11-11 11:41:34,951] INFO  org.eclipse.jetty.server.Server : Started @7377ms
[2015-11-11 11:41:34,953] INFO  com.google.gerrit.pgm.Daemon : Gerrit Code Review 2.11.4 ready
[2015-11-11 11:45:35,162] ERROR com.google.gerrit.httpd.restapi.RestApiServlet : Error in POST /changes/1/edit:publish
java.lang.ArrayIndexOutOfBoundsException: 0
        at org.eclipse.jgit.revwalk.RevCommit.getParent(RevCommit.java:348)
        at com.google.gerrit.server.git.validators.CommitValidators$ChangeHookValidator.onCommitReceived(CommitValidators.java:554)
        at com.google.gerrit.server.git.validators.CommitValidators.validateForGerritCommits(CommitValidators.java:162)
        at com.google.gerrit.server.change.PatchSetInserter.validate(PatchSetInserter.java:370)
        at com.google.gerrit.server.change.PatchSetInserter.insert(PatchSetInserter.java:221)
        at com.google.gerrit.server.edit.ChangeEditUtil.insertPatchSet(ChangeEditUtil.java:218)
        at com.google.gerrit.server.edit.ChangeEditUtil.publish(ChangeEditUtil.java:155)
        at com.google.gerrit.server.change.PublishChangeEdit$Publish.apply(PublishChangeEdit.java:101)
        at com.google.gerrit.server.change.PublishChangeEdit$Publish.apply(PublishChangeEdit.java:73)
        at com.google.gerrit.httpd.restapi.RestApiServlet.service(RestApiServlet.java:322)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
        at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
        at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
        at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
        at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
        at com.google.gerrit.httpd.GetUserFilter.doFilter(GetUserFilter.java:82)
        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
        at com.google.gwtexpui.server.CacheControlFilter.doFilter(CacheControlFilter.java:73)
        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)


Possible fix:

$ git diff
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/CommitValidators.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/CommitValidators.java
index facfb6b..01bce28 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/CommitValidators.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/validators/CommitValidators.java
@@ -551,7 +551,13 @@ public class CommitValidators {
         IdentifiedUser user = (IdentifiedUser) refControl.getCurrentUser();

         String refname = receiveEvent.refName;
-        ObjectId old = receiveEvent.commit.getParent(0);
+        ObjectId old;
+
+        try {
+          old = receiveEvent.commit.getParent(0);
+        } catch(ArrayIndexOutOfBoundsException e) {
+          old = ObjectId.zeroId();
+        }

         if (receiveEvent.command.getRefName().startsWith(REFS_CHANGES)) {
           /*
Nov 11, 2015
Project Member #1 david.pu...@sonymobile.com
https://gerrit-review.googlesource.com/#/c/72330/
Status: Submitted
Labels: FixedIn-2.11.5
Nov 12, 2015
Project Member #2 david.pu...@sonymobile.com
(No comment was entered for this change.)
Status: Released
Sign in to add a comment

Powered by Google Project Hosting