This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-changes-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new baee0a0  Report the status code when a failed Jira response has no 
entity
baee0a0 is described below

commit baee0a0516ba77f0914e0a41f2cc80149bcd4aa8
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Thu Nov 26 21:08:44 2026 +0000

    Report the status code when a failed Jira response has no entity
    
    A 204 or 304 reply made reportErrors throw NullPointerException instead of 
MojoExecutionException.
---
 .../plugins/changes/jira/RestJiraDownloader.java   |  6 ++-
 .../changes/jira/RestJiraDownloaderTest.java       | 43 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/changes/jira/RestJiraDownloader.java 
b/src/main/java/org/apache/maven/plugins/changes/jira/RestJiraDownloader.java
index ac96ae3..72bda0f 100644
--- 
a/src/main/java/org/apache/maven/plugins/changes/jira/RestJiraDownloader.java
+++ 
b/src/main/java/org/apache/maven/plugins/changes/jira/RestJiraDownloader.java
@@ -49,6 +49,7 @@ import 
org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
 import org.apache.hc.client5.http.impl.classic.HttpClients;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpStatus;
@@ -433,8 +434,9 @@ public class RestJiraDownloader {
         }
     }
 
-    private void reportErrors(ClassicHttpResponse resp) throws IOException, 
MojoExecutionException {
-        String contentTypeHeader = resp.getEntity().getContentType();
+    void reportErrors(ClassicHttpResponse resp) throws IOException, 
MojoExecutionException {
+        HttpEntity entity = resp.getEntity();
+        String contentTypeHeader = entity != null ? entity.getContentType() : 
null;
         ContentType contentType = contentTypeHeader != null ? 
ContentType.parseLenient(contentTypeHeader) : null;
         if (contentType != null && 
ContentType.APPLICATION_JSON.getMimeType().equals(contentType.getMimeType())) {
             JsonNode errorTree = getResponseTree(resp);
diff --git 
a/src/test/java/org/apache/maven/plugins/changes/jira/RestJiraDownloaderTest.java
 
b/src/test/java/org/apache/maven/plugins/changes/jira/RestJiraDownloaderTest.java
new file mode 100644
index 0000000..c45e00b
--- /dev/null
+++ 
b/src/test/java/org/apache/maven/plugins/changes/jira/RestJiraDownloaderTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.changes.jira;
+
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class RestJiraDownloaderTest {
+
+    @Test
+    void reportErrorsWithoutEntityReportsStatusCode() {
+        ClassicHttpResponse response = mock(ClassicHttpResponse.class);
+        when(response.getCode()).thenReturn(204);
+        when(response.getEntity()).thenReturn(null);
+
+        MojoExecutionException e =
+                assertThrows(MojoExecutionException.class, () -> new 
RestJiraDownloader().reportErrors(response));
+
+        assertTrue(e.getMessage().contains("response 204"), e.getMessage());
+    }
+}

Reply via email to