Skip to content

Commit ce4631b

Browse files
committed
code fix
re-fetch version and InstanceType if null
1 parent adb1131 commit ce4631b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

splunk/src/main/java/com/splunk/Service.java

+6
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,9 @@ public void setBearerToken(String value) {
13561356

13571357

13581358
public boolean enableV2SearchApi(){
1359+
if(null == this.instanceType){
1360+
this.instanceType = this.getInfo().getInstanceType();
1361+
}
13591362
if(this.instanceType.equalsIgnoreCase("cloud")) {
13601363
return versionIsAtLeast("9.0.2209");
13611364
}else{
@@ -1411,6 +1414,9 @@ boolean versionIsEarlierThan(String version) {
14111414
* or 1 if this version is greater than the given version.
14121415
*/
14131416
public int versionCompare(String otherVersion) {
1417+
if(null == this.version){
1418+
this.version = this.getInfo().getVersion();
1419+
}
14141420
String[] components1 = this.version.split("\\.");
14151421
String[] components2 = otherVersion.split("\\.");
14161422
int numComponents = Math.max(components1.length, components2.length);

splunk/src/test/java/com/splunk/ServiceTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,19 @@ public void testEnableV2Api(){
735735
}
736736
}
737737

738+
/*
739+
Test when Service instance is created using token, it doesn't result in Null Pointer while accessing instanceType and version
740+
*/
741+
@Test
742+
public void testServiceWithTokenAuth(){
743+
Service newService = new Service(service.getHost());
744+
newService.setToken(service.getToken());
745+
try{
746+
newService.enableV2SearchApi();
747+
newService.versionCompare("9.0.2");
748+
}catch (Exception ex){
749+
Assert.assertNull(ex);
750+
}
751+
}
752+
738753
}

0 commit comments

Comments
 (0)