Skip to content

Commit

Permalink
null and immutable list safe checks (#240)
Browse files Browse the repository at this point in the history
* null and immutable list safe checks
  • Loading branch information
Patrick Duin authored May 16, 2022
1 parent ca9cdc6 commit f969d04
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.10.3] - 2022-04-16
### Fixes
* Potential exception when `set_ugi` has immutable list or null-value groups argument.

## [3.10.2] - 2022-04-19
### Changed
* Caching `set_ugi` call in clients to prevent unnecessary calls to metastores.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@
*/
package com.hotels.bdp.waggledance.client;

import java.util.Collections;
import java.util.ArrayList;
import java.util.List;

public class HiveUgiArgs {

public static final HiveUgiArgs WAGGLE_DANCE_DEFAULT = new HiveUgiArgs("waggledance", Collections.emptyList());
public static final HiveUgiArgs WAGGLE_DANCE_DEFAULT = new HiveUgiArgs("waggledance", null);

private final String user;
private final List<String> groups;

public HiveUgiArgs(String user, List<String> groups) {
this.user = user;
this.groups = groups;
if (groups == null) {
this.groups = new ArrayList<>();
} else {
this.groups = new ArrayList<>(groups);
}
}

public String getUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.hotels.bdp.waggledance.client;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collections;

import org.junit.Test;

public class HiveUgiArgsTest {

@Test
public void groups() throws Exception {
HiveUgiArgs args = new HiveUgiArgs("user", new ArrayList<>());
assertThat("user", is(args.getUser()));
asssertThatListIsMutatable(args);
}

private void asssertThatListIsMutatable(HiveUgiArgs args) {
assertThat(args.getGroups().size(), is(0));
// List should be mutable, Hive code potentially mutates it.
args.getGroups().add("user");
assertThat(args.getGroups().size(), is(1));
}

@Test
public void groupDefaults() throws Exception {
HiveUgiArgs args = HiveUgiArgs.WAGGLE_DANCE_DEFAULT;
assertThat("waggledance", is(args.getUser()));
asssertThatListIsMutatable(args);
}

@Test
public void groupsImmutable() throws Exception {
HiveUgiArgs args = new HiveUgiArgs("user", Collections.emptyList());
assertThat("user", is(args.getUser()));
asssertThatListIsMutatable(args);
}

@Test
public void groupsNull() throws Exception {
HiveUgiArgs args = new HiveUgiArgs("user", null);
assertThat("user", is(args.getUser()));
assertTrue(args.getGroups().isEmpty());
}

}

0 comments on commit f969d04

Please sign in to comment.