From b5740b7672344bff38f178c048822b4aecd8239f Mon Sep 17 00:00:00 2001 From: S L Date: Fri, 10 Apr 2015 01:05:15 +0200 Subject: [PATCH 1/2] Avoid NPE as discussed in https://github.com/ktoso/maven-git-commit-id-plugin/issues/57 --- src/main/java/pl/project13/maven/git/JGitProvider.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/pl/project13/maven/git/JGitProvider.java b/src/main/java/pl/project13/maven/git/JGitProvider.java index 9778217d..8d11122e 100644 --- a/src/main/java/pl/project13/maven/git/JGitProvider.java +++ b/src/main/java/pl/project13/maven/git/JGitProvider.java @@ -83,12 +83,16 @@ protected String getBuildAuthorEmail() { protected void prepareGitToExtractMoreDetailedReproInformation() throws MojoExecutionException { try { // more details parsed out bellow - Ref HEAD = git.getRef(Constants.HEAD); - if (HEAD == null) { + Ref head = git.getRef(Constants.HEAD); + if (head == null) { throw new MojoExecutionException("Could not get HEAD Ref, are you sure you've set the dotGitDirectory property of this plugin to a valid path?"); } revWalk = new RevWalk(git); - headCommit = revWalk.parseCommit(HEAD.getObjectId()); + ObjectId headObjectId = head.getObjectId(); + if(headObjectId == null){ + throw new MojoExecutionException("Could not get HEAD Ref, are you sure you've some commits in the dotGitDirectory?"); + } + headCommit = revWalk.parseCommit(headObjectId); revWalk.markStart(headCommit); } catch (MojoExecutionException e) { throw e; From 313954327e6384ada5d80119a498be50b8ef0bdb Mon Sep 17 00:00:00 2001 From: S L Date: Fri, 10 Apr 2015 01:37:34 +0200 Subject: [PATCH 2/2] reword you've -> you have --- src/main/java/pl/project13/maven/git/JGitProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/pl/project13/maven/git/JGitProvider.java b/src/main/java/pl/project13/maven/git/JGitProvider.java index 8d11122e..2e661ab3 100644 --- a/src/main/java/pl/project13/maven/git/JGitProvider.java +++ b/src/main/java/pl/project13/maven/git/JGitProvider.java @@ -85,12 +85,12 @@ protected void prepareGitToExtractMoreDetailedReproInformation() throws MojoExec // more details parsed out bellow Ref head = git.getRef(Constants.HEAD); if (head == null) { - throw new MojoExecutionException("Could not get HEAD Ref, are you sure you've set the dotGitDirectory property of this plugin to a valid path?"); + throw new MojoExecutionException("Could not get HEAD Ref, are you sure you have set the dotGitDirectory property of this plugin to a valid path?"); } revWalk = new RevWalk(git); ObjectId headObjectId = head.getObjectId(); if(headObjectId == null){ - throw new MojoExecutionException("Could not get HEAD Ref, are you sure you've some commits in the dotGitDirectory?"); + throw new MojoExecutionException("Could not get HEAD Ref, are you sure you have some commits in the dotGitDirectory?"); } headCommit = revWalk.parseCommit(headObjectId); revWalk.markStart(headCommit);