Skip to content

Commit

Permalink
Followup on #12410: Fix caller class check to use string literals to …
Browse files Browse the repository at this point in the history
…allow private/pkg-private classes
  • Loading branch information
uschindler committed Jul 3, 2023
1 parent f668cfd commit 9ffc625
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.security.PrivilegedAction;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.apache.lucene.util.SuppressForbidden;
import org.apache.lucene.util.VectorUtil;

Expand Down Expand Up @@ -162,11 +162,8 @@ private static boolean isClientVM() {
}
}

private static boolean isValidCaller(String cn) {
// add any class that is allowed to call getInstance()
// NOTE: the list here is lazy
return Stream.of(VectorUtil.class).map(Class::getName).anyMatch(cn::equals);
}
// add all possible callers here as FQCN:
private static final Set<String> VALID_CALLERS = Set.of("org.apache.lucene.util.VectorUtil");

private static void ensureCaller() {
final boolean validCaller =
Expand All @@ -176,7 +173,7 @@ private static void ensureCaller() {
s.skip(2)
.limit(1)
.map(StackFrame::getClassName)
.allMatch(VectorizationProvider::isValidCaller));
.allMatch(VALID_CALLERS::contains));
if (!validCaller) {
throw new UnsupportedOperationException(
"VectorizationProvider is internal and can only be used by known Lucene classes.");
Expand Down

0 comments on commit 9ffc625

Please sign in to comment.