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

OAK-11602 : removed usage of Guava's ImmutableSet.copyOf with LinkedSet #2178

Merged
merged 3 commits into from
Mar 16, 2025
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 @@ -21,6 +21,7 @@
import org.apache.jackrabbit.api.security.user.UserManager;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.basic.AutoMembershipConfig;
import org.apache.jackrabbit.oak.spi.security.principal.GroupPrincipals;
import org.jetbrains.annotations.NotNull;
Expand All @@ -32,6 +33,7 @@
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -220,7 +222,7 @@ private Map<Principal, Group> collectGlobalAutoMembershipPrincipals(@NotNull Str
}
}
// only cache the principal instance but not the group (tree might become disconnected)
principalMap.put(idpName, ImmutableSet.copyOf(map.keySet()));
principalMap.put(idpName, Collections.unmodifiableSet(SetUtils.toLinkedSet(map.keySet())));
} else {
// resolve Group objects from cached principals
principalMap.get(idpName).forEach(groupPrincipal -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef;
Expand Down Expand Up @@ -199,7 +200,7 @@ private Map<String, Set<String>> getAutomembership(boolean memberIsGroup) {

private static void updateAutoMembershipMap(@NotNull Map<String, Set<String>> map, @NotNull String syncHandlerName,
@NotNull String idpName, @NotNull String[] membership) {
Set<String> userMembership = ImmutableSet.copyOf(membership);
Set<String> userMembership = Collections.unmodifiableSet(SetUtils.toLinkedSet(membership));
Set<String> previous = map.put(idpName, userMembership);
if (previous != null) {
String msg = previous.equals(userMembership) ? "Duplicate" : "Colliding";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.memory.PropertyValues;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef;
Expand Down Expand Up @@ -327,7 +328,7 @@ public boolean isMember(@NotNull Group group, @NotNull Authorizable authorizable
return Collections.emptyIterator();
}

Set<Value> valueSet = ImmutableSet.copyOf(vs);
Set<Value> valueSet = Collections.unmodifiableSet(SetUtils.toLinkedSet(vs));
Iterator<Group> declared = Iterators.filter(Iterators.transform(valueSet.iterator(), value -> {
try {
String groupPrincipalName = value.getString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authentication.external.ProtectionConfig;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Activate;
Expand Down Expand Up @@ -58,8 +59,8 @@ public class ProtectionConfigImpl implements ProtectionConfig {

@Activate
protected void activate(Map<String, Object> properties) {
propertyNames = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0]));
nodeNames = ImmutableSet.copyOf(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0]));
propertyNames = Collections.unmodifiableSet(SetUtils.toLinkedSet(PropertiesUtil.toStringArray(properties.get("propertyNames"), new String[0])));
nodeNames = Collections.unmodifiableSet(SetUtils.toLinkedSet(PropertiesUtil.toStringArray(properties.get("nodeNames"), new String[0])));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import org.apache.jackrabbit.oak.benchmark.ReadDeepTreeTest;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -86,7 +87,7 @@ protected void beforeSuite() throws Exception {
createForEachPrincipal(principal, acMgr, allPrivileges);

adminSession.save();
nodeSet = ImmutableSet.copyOf(nodePaths);
nodeSet = SetUtils.toLinkedSet(nodePaths);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a test case, so no need for Immutability here.

}

private void createForEachPrincipal(@NotNull Principal pGrantedRead, @NotNull JackrabbitAccessControlManager acMgr, @NotNull List<Privilege> allPrivileges) throws RepositoryException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static <E> Set<E> newIdentityHashSet() {
* @param <T> the type of the elements
*/
@NotNull
public static <T> Set<T> toLinkedSet(@NotNull final Iterable<T> iterable) {
public static <T> Set<T> toLinkedSet(@NotNull final Iterable<? extends T> iterable) {
Objects.requireNonNull(iterable);
final Set<T> result = new LinkedHashSet<>();
iterable.forEach(result::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public MountInfo(String name, boolean readOnly, List<String> pathsSupportingFrag
this.readOnly = readOnly;
this.pathFragmentName = "oak:mount-" + name;
this.includedPaths = cleanCopy(includedPaths);
this.pathsSupportingFragments = ImmutableSet.copyOf(pathsSupportingFragments);
this.pathsSupportingFragments = Collections.unmodifiableSet(SetUtils.toLinkedSet(pathsSupportingFragments));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package org.apache.jackrabbit.oak.spi.observation;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.jackrabbit.guava.common.collect.ImmutableSet;

import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
import org.apache.jackrabbit.oak.commons.json.JsopReader;
import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
Expand Down Expand Up @@ -74,11 +76,11 @@ public final class ChangeSet {
ChangeSet(int maxPathDepth, Set<String> parentPaths, Set<String> parentNodeNames, Set<String> parentNodeTypes,
Set<String> propertyNames, Set<String> allNodeTypes) {
this.maxPathDepth = maxPathDepth;
this.parentPaths = parentPaths == null ? null : ImmutableSet.copyOf(parentPaths);
this.parentNodeNames = parentNodeNames == null ? null : ImmutableSet.copyOf(parentNodeNames);
this.parentNodeTypes = parentNodeTypes == null ? null : ImmutableSet.copyOf(parentNodeTypes);
this.propertyNames = propertyNames == null ? null : ImmutableSet.copyOf(propertyNames);
this.allNodeTypes = allNodeTypes == null ? null : ImmutableSet.copyOf(allNodeTypes);
this.parentPaths = parentPaths == null ? null : Collections.unmodifiableSet(SetUtils.toLinkedSet(parentPaths));
this.parentNodeNames = parentNodeNames == null ? null : Collections.unmodifiableSet(SetUtils.toLinkedSet(parentNodeNames));
this.parentNodeTypes = parentNodeTypes == null ? null : Collections.unmodifiableSet(SetUtils.toLinkedSet(parentNodeTypes));
this.propertyNames = propertyNames == null ? null : Collections.unmodifiableSet(SetUtils.toLinkedSet(propertyNames));
this.allNodeTypes = allNodeTypes == null ? null : Collections.unmodifiableSet(SetUtils.toLinkedSet(allNodeTypes));

boolean hitsMaxPathDepth = false;
if (parentPaths != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
import org.apache.jackrabbit.oak.spi.commit.CommitHook;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
Expand All @@ -41,7 +42,6 @@
import java.util.stream.StreamSupport;

import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.guava.common.collect.ImmutableSet.copyOf;
import static java.util.Collections.emptySet;

/**
Expand Down Expand Up @@ -402,7 +402,7 @@ private Builder() {}
@NotNull
public Builder include(@NotNull Set<String> paths) {
if (!requireNonNull(paths).isEmpty()) {
this.includePaths = copyOf(paths);
this.includePaths = Collections.unmodifiableSet(SetUtils.toLinkedSet(paths));
}
return this;
}
Expand All @@ -416,7 +416,7 @@ public Builder include(@NotNull Set<String> paths) {
*/
@NotNull
public Builder include(@NotNull String... paths) {
return include(copyOf(requireNonNull(paths)));
return include(Collections.unmodifiableSet(SetUtils.toLinkedSet(requireNonNull(paths))));
}

/**
Expand All @@ -442,7 +442,7 @@ public Builder preserve(@NotNull boolean preserveOnTarget) {
@NotNull
public Builder exclude(@NotNull Set<String> paths) {
if (!requireNonNull(paths).isEmpty()) {
this.excludePaths = copyOf(paths);
this.excludePaths = Collections.unmodifiableSet(SetUtils.toLinkedSet(paths));
}
return this;
}
Expand All @@ -456,7 +456,7 @@ public Builder exclude(@NotNull Set<String> paths) {
*/
@NotNull
public Builder exclude(@NotNull String... paths) {
return exclude(copyOf(requireNonNull(paths)));
return exclude(Collections.unmodifiableSet(SetUtils.toLinkedSet(requireNonNull(paths))));
}

/**
Expand All @@ -469,7 +469,7 @@ public Builder exclude(@NotNull String... paths) {
@NotNull
public Builder supportFragment(@NotNull Set<String> paths) {
if (!requireNonNull(paths).isEmpty()) {
this.fragmentPaths = copyOf(paths);
this.fragmentPaths = Collections.unmodifiableSet(SetUtils.toLinkedSet(paths));
}
return this;
}
Expand All @@ -483,7 +483,7 @@ public Builder supportFragment(@NotNull Set<String> paths) {
*/
@NotNull
public Builder supportFragment(@NotNull String... paths) {
return supportFragment(copyOf(requireNonNull(paths)));
return supportFragment(Collections.unmodifiableSet(SetUtils.toLinkedSet(requireNonNull(paths))));
}

/**
Expand All @@ -496,7 +496,7 @@ public Builder supportFragment(@NotNull String... paths) {
@NotNull
public Builder excludeFragments(@NotNull Set<String> fragments) {
if (!requireNonNull(fragments).isEmpty()) {
this.excludeFragments = copyOf(fragments);
this.excludeFragments = Collections.unmodifiableSet(SetUtils.toLinkedSet(fragments));
}
return this;
}
Expand All @@ -510,7 +510,7 @@ public Builder excludeFragments(@NotNull Set<String> fragments) {
*/
@NotNull
public Builder excludeFragments(@NotNull String... fragments) {
return exclude(copyOf(requireNonNull(fragments)));
return exclude(Collections.unmodifiableSet(SetUtils.toLinkedSet(requireNonNull(fragments))));
}

/**
Expand All @@ -523,7 +523,7 @@ public Builder excludeFragments(@NotNull String... fragments) {
@NotNull
public Builder merge(@NotNull Set<String> paths) {
if (!requireNonNull(paths).isEmpty()) {
this.mergePaths = copyOf(paths);
this.mergePaths = Collections.unmodifiableSet(SetUtils.toLinkedSet(paths));
}
return this;
}
Expand All @@ -537,7 +537,7 @@ public Builder merge(@NotNull Set<String> paths) {
*/
@NotNull
public Builder merge(@NotNull String... paths) {
return merge(copyOf(requireNonNull(paths)));
return merge(Collections.unmodifiableSet(SetUtils.toLinkedSet(requireNonNull(paths))));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.jackrabbit.guava.common.collect.ImmutableList;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.commit.MoveTracker;
import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
import org.apache.jackrabbit.oak.spi.security.ConfigurationBase;
Expand All @@ -44,6 +45,7 @@
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import java.security.Principal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -176,7 +178,7 @@ private CredentialsSupport newCredentialsSupport() {
} else if (size == 1) {
return credentialsSupport.values().iterator().next();
} else {
return CompositeCredentialsSupport.newInstance(() -> ImmutableSet.copyOf(credentialsSupport.values()));
return CompositeCredentialsSupport.newInstance(() -> Collections.unmodifiableSet(SetUtils.toLinkedSet(credentialsSupport.values())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
import org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants;
import org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants;
Expand All @@ -34,6 +35,7 @@

import javax.jcr.NamespaceRegistry;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -99,7 +101,7 @@ class CurrentPattern implements RestrictionPattern {

CurrentPattern(@NotNull String treePath, @NotNull Iterable<String> propertyNames) {
this.treePath = treePath;
this.propertyNames = ImmutableSet.copyOf(propertyNames);
this.propertyNames = Collections.unmodifiableSet(SetUtils.toLinkedSet(propertyNames));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*/
package org.apache.jackrabbit.oak.security.authorization.restriction;

import java.util.Collections;
import java.util.Set;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,7 +39,7 @@ class ItemNamePattern implements RestrictionPattern {
private final Set<String> names;

ItemNamePattern(Iterable<String> names) {
this.names = ImmutableSet.copyOf(names);
this.names = Collections.unmodifiableSet(SetUtils.toLinkedSet(names));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package org.apache.jackrabbit.oak.security.authorization.restriction;

import java.util.Collections;
import java.util.Set;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
import org.jetbrains.annotations.NotNull;
Expand All @@ -41,7 +43,7 @@ class NodeTypePattern implements RestrictionPattern {
private final Set<String> nodeTypeNames;

NodeTypePattern(@NotNull Iterable<String> nodeTypeNames) {
this.nodeTypeNames = ImmutableSet.copyOf(nodeTypeNames);
this.nodeTypeNames = Collections.unmodifiableSet(SetUtils.toLinkedSet(nodeTypeNames));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*/
package org.apache.jackrabbit.oak.security.authorization.restriction;

import java.util.Collections;
import java.util.Set;
import org.apache.jackrabbit.guava.common.collect.ImmutableSet;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.apache.jackrabbit.util.Text;
import org.jetbrains.annotations.NotNull;
Expand All @@ -45,7 +47,7 @@ class PrefixPattern implements RestrictionPattern {
private final Set<String> prefixes;

PrefixPattern(@NotNull Iterable<String> prefixes) {
this.prefixes = ImmutableSet.copyOf(prefixes);
this.prefixes = Collections.unmodifiableSet(SetUtils.toLinkedSet(prefixes));
}

@Override
Expand Down
Loading
Loading