Fix NPE in StoredCommentLink#fromInfo This commit fixes an issue where a cast from a boxed Boolean to a primitive boolean would provoke an NPE. A test is added to verify the behavior. The test fails if 'boolean' would be used. Change-Id: I8608da5fa77cf1ce380adb62ea0c79d72b46fbe5
diff --git a/java/com/google/gerrit/entities/StoredCommentLinkInfo.java b/java/com/google/gerrit/entities/StoredCommentLinkInfo.java index e70bf1e..ce24d31 100644 --- a/java/com/google/gerrit/entities/StoredCommentLinkInfo.java +++ b/java/com/google/gerrit/entities/StoredCommentLinkInfo.java
@@ -68,7 +68,7 @@ } /** Creates and returns a new {@link StoredCommentLinkInfo} instance with the same values. */ - public static StoredCommentLinkInfo fromInfo(CommentLinkInfo src, boolean enabled) { + public static StoredCommentLinkInfo fromInfo(CommentLinkInfo src, Boolean enabled) { return builder(src.name) .setMatch(src.match) .setLink(src.link)
diff --git a/javatests/com/google/gerrit/server/project/ProjectConfigTest.java b/javatests/com/google/gerrit/server/project/ProjectConfigTest.java index 606e147..6ea6a33 100644 --- a/javatests/com/google/gerrit/server/project/ProjectConfigTest.java +++ b/javatests/com/google/gerrit/server/project/ProjectConfigTest.java
@@ -598,6 +598,27 @@ } @Test + public void readCommentLinksNoHtmlOrLinkAndMissingEnabled() throws Exception { + RevCommit rev = + tr.commit() + .add( + "project.config", + "[commentlink \"bugzilla\"]\n \tlink = http://bugs.example.com/show_bug.cgi?id=$2" + + "\n \tmatch = \"(bug\\\\s+#?)(\\\\d+)\"\n") + .create(); + ProjectConfig cfg = read(rev); + assertThat(cfg.getCommentLinkSections()) + .containsExactly( + StoredCommentLinkInfo.builder("bugzilla") + .setMatch("(bug\\s+#?)(\\d+)") + .setLink("http://bugs.example.com/show_bug.cgi?id=$2") + .build()); + StoredCommentLinkInfo stored = Iterables.getOnlyElement(cfg.getCommentLinkSections()); + assertThat(StoredCommentLinkInfo.fromInfo(stored.toInfo(), stored.getEnabled())) + .isEqualTo(stored); + } + + @Test public void readCommentLinkInvalidPattern() throws Exception { RevCommit rev = tr.commit()