Skip to content

Commit

Permalink
fix #3047: NPE when getting version when there is no build date
Browse files Browse the repository at this point in the history
* Add null check for build date before trying to parse it.

Signed-off-by: Yevgeny Kuznetsov <[email protected]>
  • Loading branch information
yevgenykuz authored and manusa committed Apr 30, 2021
1 parent b4f36db commit 131139b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Fix #3020: annotations should now properly have their associated values when processing CRDs from the API
* Fix #3027: fix NPE when sorting events in KubernetesResourceUtil
* Fix missing entry for Trigger in TektonTriggersResourceMappingProvider
* Fix #3047: NPE when getting version when there is no build date

#### Improvements
* Fix #2788: Support FIPS mode in kubernetes-client with BouncyCastleFipsProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public Builder(VersionInfo versionInfo) {
}

public Builder withBuildDate(String buildDate) throws ParseException {
this.versionInfo.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
if (buildDate != null) {
this.versionInfo.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.text.SimpleDateFormat;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

@EnableKubernetesMockClient
public class VersionInfoTest {
Expand All @@ -47,6 +48,23 @@ public void testClusterVersioning() throws ParseException {
assertEquals("3", client.getVersion().getMajor());
assertEquals("6", client.getVersion().getMinor());
assertEquals(118, client.getVersion().getBuildDate().getYear());
assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse("2018-03-01T14:27:17Z").getTime(), client.getVersion().getBuildDate().getTime());
assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse("2018-03-01T14:27:17Z").getTime(),
client.getVersion().getBuildDate().getTime());
}

@Test
public void testClusterVersioningWithMissingBuildDate() {
server.expect().withPath("/version").andReturn(200, "{" +
" \"gitCommit\": \"e6301f88a8\"," +
" \"gitVersion\": \"v1.6.1+5115d708d7\"," +
" \"major\": \"3\"," +
" \"minor\": \"6\"" +
"}").always();

assertEquals("v1.6.1+5115d708d7", client.getVersion().getGitVersion());
assertEquals("e6301f88a8", client.getVersion().getGitCommit());
assertEquals("3", client.getVersion().getMajor());
assertEquals("6", client.getVersion().getMinor());
assertNull(client.getVersion().getBuildDate());
}
}

0 comments on commit 131139b

Please sign in to comment.