Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.0] Replace remaining 'blacklist' with 'denylist' in internal class and method names #2813

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void putBinding(BindingImpl<?> binding) {
}

// prevent the parent from creating a JIT binding for this key
injector.state.parent().blacklist(key);
injector.state.parent().denylist(key);
injector.state.putBinding(key, binding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ public List<TypeListenerBinding> getTypeListenerBindings() {
}

@Override
public void blacklist(Key<?> key) {
parent.blacklist(key);
public void denylist(Key<?> key) {
parent.denylist(key);
denylistedKeys.add(key);
}

@Override
public boolean isBlacklisted(Key<?> key) {
public boolean isDenylisted(Key<?> key) {
return denylistedKeys.contains(key);
}

@Override
public void clearBlacklisted() {
public void clearDenylisted() {
denylistedKeys = new WeakKeySet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ public T get(Errors errors, InternalContext context, Dependency<?> dependency) t
* other ancestor injectors until this injector is tried.
*/
private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors errors) throws ErrorsException {
if (state.isBlacklisted(key)) {
if (state.isDenylisted(key)) {
throw errors.childBindingAlreadySet(key).toException();
}

BindingImpl<T> binding = createJustInTimeBinding(key, errors);
state.parent().blacklist(key);
state.parent().denylist(key);
jitBindings.put(key, binding);
return binding;
}
Expand All @@ -555,7 +555,7 @@ private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors e
* if the binding cannot be created.
*/
<T> BindingImpl<T> createJustInTimeBinding(Key<T> key, Errors errors) throws ErrorsException {
if (state.isBlacklisted(key)) {
if (state.isDenylisted(key)) {
throw errors.childBindingAlreadySet(key).toException();
}

Expand Down Expand Up @@ -805,7 +805,7 @@ public String toString() {

// ES_GUICE: clear caches
public void clearCache() {
state.clearBlacklisted();
state.clearDenylisted();
constructors = new ConstructorInjectorStore(this);
membersInjectorStore = new MembersInjectorStore(this, state.getTypeListenerBindings());
jitBindings = new HashMap<>();
Expand Down
12 changes: 6 additions & 6 deletions server/src/main/java/org/opensearch/common/inject/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public List<TypeListenerBinding> getTypeListenerBindings() {
}

@Override
public void blacklist(Key<?> key) {}
public void denylist(Key<?> key) {}

@Override
public boolean isBlacklisted(Key<?> key) {
public boolean isDenylisted(Key<?> key) {
return true;
}

@Override
public void clearBlacklisted() {}
public void clearDenylisted() {}

@Override
public void makeAllBindingsToEagerSingletons(Injector injector) {}
Expand Down Expand Up @@ -167,13 +167,13 @@ public Object lock() {
* denylist their bound keys on their parent injectors to prevent just-in-time bindings on the
* parent injector that would conflict.
*/
void blacklist(Key<?> key);
void denylist(Key<?> key);

/**
* Returns true if {@code key} is forbidden from being bound in this injector. This indicates that
* one of this injector's descendent's has bound the key.
*/
boolean isBlacklisted(Key<?> key);
boolean isDenylisted(Key<?> key);

/**
* Returns the shared lock for all injector data. This is a low-granularity, high-contention lock
Expand All @@ -182,7 +182,7 @@ public Object lock() {
Object lock();

// ES_GUICE: clean denylist keys
void clearBlacklisted();
void clearDenylisted();

void makeAllBindingsToEagerSingletons(Injector injector);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
*
* Each denylist pattern is a suffix match on the path. Empty patterns are not allowed.
*/
final class BlacklistedPathPatternMatcher {
final class DenylistedPathPatternMatcher {
private final Pattern pattern;

/**
* Constructs a new <code>DenylistedPathPatternMatcher</code> instance from the provided suffix pattern.
*
* @param p The suffix pattern. Must be a non-empty string.
*/
BlacklistedPathPatternMatcher(String p) {
DenylistedPathPatternMatcher(String p) {
// guard against accidentally matching everything as an empty string lead to the pattern ".*" which matches everything
if (p == null || p.trim().isEmpty()) {
throw new IllegalArgumentException("Empty denylist patterns are not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public abstract class OpenSearchClientYamlSuiteTestCase extends OpenSearchRestTe
*/
private static final String PATHS_SEPARATOR = "(?<!\\\\),";

private static List<BlacklistedPathPatternMatcher> denylistPathMatchers;
private static List<DenylistedPathPatternMatcher> denylistPathMatchers;
private static ClientYamlTestExecutionContext restTestExecutionContext;
private static ClientYamlTestExecutionContext adminExecutionContext;
private static ClientYamlTestClient clientYamlTestClient;
Expand Down Expand Up @@ -157,11 +157,11 @@ public void initAndResetContext() throws Exception {
final String[] denylist = resolvePathsProperty(REST_TESTS_DENYLIST, null);
denylistPathMatchers = new ArrayList<>();
for (final String entry : denylist) {
denylistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
denylistPathMatchers.add(new DenylistedPathPatternMatcher(entry));
}
final String[] denylistAdditions = resolvePathsProperty(REST_TESTS_DENYLIST_ADDITIONS, null);
for (final String entry : denylistAdditions) {
denylistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
denylistPathMatchers.add(new DenylistedPathPatternMatcher(entry));
}
}
assert restTestExecutionContext != null;
Expand Down Expand Up @@ -368,12 +368,9 @@ protected RequestOptions getCatNodesVersionMasterRequestOptions() {

public void test() throws IOException {
// skip test if it matches one of the denylist globs
for (BlacklistedPathPatternMatcher denylistedPathMatcher : denylistPathMatchers) {
for (DenylistedPathPatternMatcher denylistedPathMatcher : denylistPathMatchers) {
String testPath = testCandidate.getSuitePath() + "/" + testCandidate.getTestSection().getName();
assumeFalse(
"[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted",
denylistedPathMatcher.isSuffixMatch(testPath)
);
assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: denylisted", denylistedPathMatcher.isSuffixMatch(testPath));
}

// skip test if the whole suite (yaml file) is disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import org.opensearch.test.OpenSearchTestCase;

public class BlacklistedPathPatternMatcherTests extends OpenSearchTestCase {
public class DenylistedPathPatternMatcherTests extends OpenSearchTestCase {

public void testMatchesExact() {
// suffix match
Expand Down Expand Up @@ -71,12 +71,12 @@ public void testMatchesMixedPatterns() {
}

private void assertMatch(String pattern, String path) {
BlacklistedPathPatternMatcher matcher = new BlacklistedPathPatternMatcher(pattern);
DenylistedPathPatternMatcher matcher = new DenylistedPathPatternMatcher(pattern);
assertTrue("Pattern [" + pattern + "] should have matched path [" + path + "]", matcher.isSuffixMatch(path));
}

private void assertNoMatch(String pattern, String path) {
BlacklistedPathPatternMatcher matcher = new BlacklistedPathPatternMatcher(pattern);
DenylistedPathPatternMatcher matcher = new DenylistedPathPatternMatcher(pattern);
assertFalse("Pattern [" + pattern + "] should not have matched path [" + path + "]", matcher.isSuffixMatch(path));
}
}