Skip to content

Commit

Permalink
OAK-10711 : replaced preconditions.checkNotNull with Objects.requireN…
Browse files Browse the repository at this point in the history
…otNull (apache#1480)

Co-authored-by: Rishabh Kumar <[email protected]>
Co-authored-by: Julian Reschke <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 396b3c4 commit 7fd1a13
Show file tree
Hide file tree
Showing 397 changed files with 1,603 additions and 1,612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

/**
* Extension of the {@code DefaultSyncContext} that doesn't synchronize group
Expand Down Expand Up @@ -315,7 +315,7 @@ private void createDynamicGroups(@NotNull Iterable<SyncEntry> syncEntries) throw
// since 'shortcut' is omitted if dynamic groups are enabled, there is no need to test if 'external-group' is
// null, nor trying to retrieve external group again. if it could not be resolved during 'collectSyncEntries'
// before it didn't got added to the map
checkNotNull(syncEntry.externalGroup, "Cannot create dynamic group from null ExternalIdentity.");
requireNonNull(syncEntry.externalGroup, "Cannot create dynamic group from null ExternalIdentity.");

// lookup of existing group by ID has been performed already including check for conflicting authorizable
// type or principal name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import java.util.Iterator;
import java.util.List;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

final class Delegatee {

Expand Down Expand Up @@ -360,7 +360,7 @@ private Iterator<String> internalListOrphanedIdentities() {
if (syncedIdentity != null && isMyIDP(syncedIdentity)) {
try {
// nonNull-ExternalIdRef has already been asserted by 'isMyIDP'
ExternalIdentity extId = idp.getIdentity(checkNotNull(syncedIdentity.getExternalIdRef()));
ExternalIdentity extId = idp.getIdentity(requireNonNull(syncedIdentity.getExternalIdRef()));
if (extId == null) {
return syncedIdentity.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import java.util.Set;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.DynamicGroupUtil.findGroupIdInHierarchy;
import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.DynamicGroupUtil.isGroup;
import static org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.DynamicGroupUtil.isMemberProperty;
Expand All @@ -66,7 +66,7 @@ class DynamicGroupValidatorProvider extends ValidatorProvider implements Externa
this.treeProvider = treeProvider;
this.idpNamesWithDynamicGroups = idpNamesWithDynamicGroups;

this.groupRootPath = checkNotNull(UserUtil.getAuthorizableRootPath(securityProvider.getParameters(UserConfiguration.NAME), AuthorizableType.GROUP));
this.groupRootPath = requireNonNull(UserUtil.getAuthorizableRootPath(securityProvider.getParameters(UserConfiguration.NAME), AuthorizableType.GROUP));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import javax.jcr.nodetype.NodeDefinitionTemplate;
import javax.jcr.nodetype.NodeTypeTemplate;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand All @@ -56,7 +56,7 @@ public void before() throws Exception {

@NotNull
private Validator createRootValidator(@NotNull NodeState ns) {
return checkNotNull(new CugValidatorProvider().getRootValidator(ns, ns, new CommitInfo("sid", "uid")));
return requireNonNull(new CugValidatorProvider().getRootValidator(ns, ns, new CommitInfo("sid", "uid")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testReadVersionContentNoAccess() {
IdentifierManager idMgr = new IdentifierManager(testRoot);

for (String path : noReadAccess) {
String vhUUID = checkNotNull(TreeUtil.getString(root.getTree(path), JCR_VERSIONHISTORY));
String vhUUID = requireNonNull(TreeUtil.getString(root.getTree(path), JCR_VERSIONHISTORY));
String vhPath = PathUtils.concat(VERSION_STORE_PATH, versionManager.getVersionHistoryPath(vhUUID));

Tree vHistory = testRoot.getTree(vhPath);
Expand Down Expand Up @@ -218,7 +218,7 @@ public void testVersionableRemoved() throws Exception {
// cug at /content/a/b/c grants access
Tree versionable = addVersionContent("/content/a/b/c");

Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));

assertTrue(testRoot.getTree(vh.getPath()).exists());

Expand All @@ -242,7 +242,7 @@ public void testVersionableRemoved2() throws Exception {
// cug at /content/a/b/c denies access
Tree versionable = root.getTree("/content/a");

Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));

assertFalse(testRoot.getTree(vh.getPath()).exists());

Expand All @@ -263,7 +263,7 @@ public void testVersionableRemoved2() throws Exception {
@Test
public void testTreePermissionVersionable() throws Exception {
Tree versionable = root.getTree("/content/a");
Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));

CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2), EveryonePrincipal.getInstance());

Expand All @@ -287,7 +287,7 @@ public void testTreePermissionVersionable() throws Exception {
@Test
public void testTreePermissionVersionable2() throws Exception {
Tree versionable = root.getTree("/content");
Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));

CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2));

Expand All @@ -310,7 +310,7 @@ public void testTreePermissionVersionable2() throws Exception {
@Test
public void testTreePermissionVersionableUnsupportedPath() throws Exception {
Tree versionable = root.getTree(UNSUPPORTED_PATH);
Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));

CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2));

Expand All @@ -331,7 +331,7 @@ public void testTreePermissionVersionableUnsupportedPath() throws Exception {

@Test
public void testTreePermissionAtVersionableAboveSupported() throws Exception {
Tree vh = checkNotNull(versionManager.getVersionHistory(root.getTree(SUPPORTED_PATH)));
Tree vh = requireNonNull(versionManager.getVersionHistory(root.getTree(SUPPORTED_PATH)));

CugPermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH + "/a"));
TreePermission tp = getTreePermission(root, vh.getPath(), pp);
Expand All @@ -341,7 +341,7 @@ public void testTreePermissionAtVersionableAboveSupported() throws Exception {
@Test
public void testCugAtRoot() throws Exception {
Tree versionable = root.getTree(UNSUPPORTED_PATH);
String vhPath = checkNotNull(versionManager.getVersionHistory(versionable)).getPath();
String vhPath = requireNonNull(versionManager.getVersionHistory(versionable)).getPath();

try {
createCug(root, PathUtils.ROOT_PATH, EveryonePrincipal.NAME);
Expand Down Expand Up @@ -371,7 +371,7 @@ public void testCugAtRoot() throws Exception {
@Test
public void testVersionableWithUnsupportedType() throws Exception {
Tree versionable = root.getTree("/content");
Tree vh = checkNotNull(versionManager.getVersionHistory(versionable));
Tree vh = requireNonNull(versionManager.getVersionHistory(versionable));
Tree frozen = vh.getChild("1.0").getChild(JCR_FROZENNODE).getChild("a").getChild("b").getChild("c");

Tree invalidFrozen = frozen.addChild(REP_CUG_POLICY);
Expand All @@ -391,7 +391,7 @@ public void testVersionableWithCugParent() throws Exception {
Tree cc = root.getTree("/content/aa/bb/cc");
assertFalse(CugUtil.hasCug(cc));

Tree vh = checkNotNull(versionManager.getVersionHistory(cc));
Tree vh = requireNonNull(versionManager.getVersionHistory(cc));
Tree t = root.getTree("/");
CugPermissionProvider pp = createCugPermissionProvider(
ImmutableSet.of(SUPPORTED_PATH, SUPPORTED_PATH2), getTestGroupPrincipal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.util.Map;
import java.util.UUID;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NT_OAK_UNSTRUCTURED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -177,7 +177,7 @@ boolean addDefaultEntry(@Nullable String path, @NotNull Principal principal, @No
boolean addDefaultEntry(@Nullable String path, @NotNull Principal principal, @Nullable Map<String, Value> restr, @Nullable Map<String, Value[]> mvRestr, @NotNull String... privNames) throws Exception {
JackrabbitAccessControlManager jacm = getAccessControlManager(root);
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(jacm, path);
checkNotNull(acl);
requireNonNull(acl);

boolean mod = acl.addEntry(principal, privilegesFromNames(privNames), true, restr, mvRestr);
jacm.setPolicy(acl.getPath(), acl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import java.security.Principal;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static javax.jcr.Session.ACTION_READ;
import static org.apache.jackrabbit.JcrConstants.JCR_BASEVERSION;
import static org.apache.jackrabbit.JcrConstants.JCR_ISCHECKEDOUT;
Expand Down Expand Up @@ -108,7 +108,7 @@ private String getVersionPath(@NotNull String versionablePath, boolean history)
} else {
path = new IdentifierManager(root).getPath(versionable.getProperty(JCR_BASEVERSION));
}
checkNotNull(path);
requireNonNull(path);
return path;
}

Expand All @@ -122,7 +122,7 @@ private Tree getVersionTree(@NotNull String versionablePath, boolean history) {
reference = versionable.getProperty(JCR_BASEVERSION);
}
Tree t = new IdentifierManager(root).getTree(reference.getValue(Type.STRING));
checkNotNull(t);
requireNonNull(t);
return t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import java.security.Principal;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.JcrConstants.JCR_BASEVERSION;
import static org.apache.jackrabbit.JcrConstants.JCR_FROZENNODE;
import static org.apache.jackrabbit.JcrConstants.JCR_ISCHECKEDOUT;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected NamePathMapper getNamePathMapper() {
private String getPathFromReference(@NotNull String treePath, @NotNull String refProperty) {
Tree tree = root.getTree(treePath);
String path = new IdentifierManager(root).getPath(tree.getProperty(refProperty));
checkNotNull(path);
requireNonNull(path);
return path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import java.util.Set;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;

public class ElasticGlobalInitializer implements RepositoryInitializer {
Expand Down Expand Up @@ -92,7 +92,7 @@ public ElasticGlobalInitializer async() {
* @return
*/
public ElasticGlobalInitializer async(@NotNull final String async) {
this.async = checkNotNull(async);
this.async = requireNonNull(async);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DECLARING_NODE_TYPES;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
import static org.apache.jackrabbit.oak.spi.nodetype.NodeTypeConstants.NT_OAK_UNSTRUCTURED;
Expand Down Expand Up @@ -401,7 +401,7 @@ private void prepareLuceneIndexer(File workDir, NodeStore nodeStore) {
}

private void runAsyncIndex() {
checkNotNull(getAsyncIndexUpdate()).run();
requireNonNull(getAsyncIndexUpdate()).run();
}

private AsyncIndexUpdate getAsyncIndexUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

/**
* Test the effect of multiple authorization configurations on the general read
Expand Down Expand Up @@ -97,7 +97,7 @@ private static SecurityProvider newTestSecurityProvider(int cnt) {
throw new IllegalStateException();
} else {
CompositeAuthorizationConfiguration composite = (CompositeAuthorizationConfiguration) authorizationConfiguration;
final AuthorizationConfiguration defConfig = checkNotNull(composite.getDefaultConfig());
final AuthorizationConfiguration defConfig = requireNonNull(composite.getDefaultConfig());
for (int i = 0; i < cnt; i++) {
composite.addConfiguration(new TmpAuthorizationConfig(defConfig));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.jackrabbit.oak.spi.security.authorization.cug.impl.CugConfiguration;
import org.jetbrains.annotations.NotNull;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

/**
* Test the effect of multiple authorization configurations on the general read
Expand Down Expand Up @@ -86,7 +86,7 @@ private static SecurityProvider newTestSecurityProvider(@NotNull ConfigurationPa
SecurityProvider delegate = SecurityProviderBuilder.newBuilder().with(params).build();
CompositeAuthorizationConfiguration authorizationConfiguration = (CompositeAuthorizationConfiguration) delegate
.getConfiguration((AuthorizationConfiguration.class));
AuthorizationConfiguration defaultAuthorization = checkNotNull(authorizationConfiguration.getDefaultConfig());
AuthorizationConfiguration defaultAuthorization = requireNonNull(authorizationConfiguration.getDefaultConfig());
if (reverseOrder) {
authorizationConfiguration.addConfiguration(defaultAuthorization);
authorizationConfiguration.addConfiguration(new CugConfiguration(delegate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.util.concurrent.atomic.AtomicReference;


import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
import static org.apache.jackrabbit.oak.api.Type.LONG;
import static org.apache.jackrabbit.oak.api.Type.NAME;
Expand Down Expand Up @@ -232,7 +232,7 @@ class TestContext {

public TestContext(@NotNull final String title) {
LOG.trace("Setting title - {} for test context", title);
this.title = checkNotNull(title);
this.title = requireNonNull(title);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import java.util.List;
import java.util.Map;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static javax.jcr.security.Privilege.JCR_ALL;

public class PrinicipalBasedReadTest extends ReadDeepTreeTest {
Expand Down Expand Up @@ -220,7 +220,7 @@ private SecurityProvider createSecurityProvider() {
CompositeAuthorizationConfiguration authorizationConfiguration = (CompositeAuthorizationConfiguration) delegate
.getConfiguration((AuthorizationConfiguration.class));
authorizationConfiguration.withCompositionType(compositionType);
AuthorizationConfiguration defaultAuthorization = checkNotNull(authorizationConfiguration.getDefaultConfig());
AuthorizationConfiguration defaultAuthorization = requireNonNull(authorizationConfiguration.getDefaultConfig());
if (testDefault) {
authorizationConfiguration.addConfiguration(defaultAuthorization);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.apache.jackrabbit.oak.plugins.blob;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.lang.System.nanoTime;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;
import static org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status.formatTime;
import static org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.done;
Expand Down Expand Up @@ -72,8 +72,8 @@ public BlobGC(
@NotNull BlobGarbageCollector blobGarbageCollector,
@NotNull Executor executor) {
super(BlobGCMBean.class);
this.blobGarbageCollector = checkNotNull(blobGarbageCollector);
this.executor = checkNotNull(executor);
this.blobGarbageCollector = requireNonNull(blobGarbageCollector);
this.executor = requireNonNull(executor);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.apache.jackrabbit.oak.plugins.blob;

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.apache.jackrabbit.oak.commons.IOUtils.humanReadableByteCount;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -225,7 +225,7 @@ public class BlobStoreStats extends AnnotatedStandardMBean implements BlobStoreS

public BlobStoreStats(@NotNull StatisticsProvider sp) {
super(BlobStoreStatsMBean.class);
this.statisticsProvider = checkNotNull(sp);
this.statisticsProvider = requireNonNull(sp);

this.uploadHisto = sp.getHistogram(BLOB_UPLOADS, StatsOptions.DEFAULT);
this.uploadCount = sp.getMeter(BLOB_UPLOAD_COUNT, StatsOptions.DEFAULT);
Expand Down
Loading

0 comments on commit 7fd1a13

Please sign in to comment.