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-11411 : removed usage of Guava Strings.emptyToNull #2015

Merged
merged 1 commit into from
Jan 22, 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 @@ -22,6 +22,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionPattern;
import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider;
Expand Down Expand Up @@ -85,7 +86,7 @@ private final class PermissionEntryImpl implements PermissionEntry {
private final RestrictionPattern pattern;

private PermissionEntryImpl(@NotNull Tree entryTree) {
effectivePath = Strings.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
effectivePath = StringUtils.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
privilegeBits = bitsProvider.getBits(entryTree.getProperty(REP_PRIVILEGES).getValue(Type.NAMES));
if (Utils.hasRestrictions(entryTree)) {
pattern = restrictionProvider.getPattern(effectivePath, restrictionProvider.readRestrictions(effectivePath, entryTree));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private AbstractEntry createEffectiveEntry(@NotNull Tree entryTree) throws Acces
if (principal == null || !filter.canHandle(Collections.singleton(principal))) {
return null;
}
String oakPath = Strings.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
String oakPath = org.apache.jackrabbit.oak.commons.StringUtils.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
PrivilegeBits bits = privilegeBitsProvider.getBits(entryTree.getProperty(Constants.REP_PRIVILEGES).getValue(Type.NAMES));

RestrictionProvider rp = mgrProvider.getRestrictionProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.collections.MapUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.tree.TreeUtil;
Expand Down Expand Up @@ -75,7 +76,7 @@ class PrincipalPolicyImpl extends AbstractAccessControlList implements Principal
}

boolean addEntry(@NotNull Tree entryTree, @NotNull Collection<String> oakPathToFilter) throws AccessControlException {
String oakPath = Strings.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
String oakPath = StringUtils.emptyToNull(TreeUtil.getString(entryTree, REP_EFFECTIVE_PATH));
if (Utils.hasValidRestrictions(oakPath, entryTree, restrictionProvider)) {
PrivilegeBits bits = privilegeBitsProvider.getBits(entryTree.getProperty(Constants.REP_PRIVILEGES).getValue(Type.NAMES));
Set<Restriction> restrictions = Utils.readRestrictions(restrictionProvider, oakPath, entryTree);
Expand Down Expand Up @@ -246,7 +247,7 @@ private static String extractPathFromRestrictions(@Nullable Map<String, Value> r
}

// retrieve path from restrictions and filter that restriction entry for further processing
return Strings.emptyToNull(restrictions.get(jcrName).getString());
return StringUtils.emptyToNull(restrictions.get(jcrName).getString());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.conditions.Validate;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
Expand Down Expand Up @@ -308,7 +309,7 @@ private void applyTo(@NotNull PrincipalPolicyImpl policy) throws RepositoryExcep
log.error("Missing rep:effectivePath for entry {} of policy at {}", this, policy.getOakPath());
throw new ConstraintViolationException("Entries for PrincipalAccessControlList must specify an effective path.");
}
policy.addEntry(Strings.emptyToNull(effectivePath), Iterables.toArray(privileges, Privilege.class), restrictions, mvRestrictions);
policy.addEntry(StringUtils.emptyToNull(effectivePath), Iterables.toArray(privileges, Privilege.class), restrictions, mvRestrictions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.conditions.Validate;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate;
Expand Down Expand Up @@ -199,7 +200,7 @@ private void validateRestrictions(@NotNull NodeState nodeState) throws CommitFai
Tree parent = verifyNotNull(parentAfter);
if (NT_REP_PRINCIPAL_ENTRY.equals(TreeUtil.getPrimaryTypeName(parent))) {
try {
String oakPath = Strings.emptyToNull(TreeUtil.getString(parent, REP_EFFECTIVE_PATH));
String oakPath = StringUtils.emptyToNull(TreeUtil.getString(parent, REP_EFFECTIVE_PATH));
mgrProvider.getRestrictionProvider().validateRestrictions(oakPath, parent);
} catch (AccessControlException e) {
throw new CommitFailedException(ACCESS_CONTROL, 35, "Invalid restrictions", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void init() throws DataStoreException {
try {
Utils.setProxyIfNeeded(properties);
createBlobContainer = PropertiesUtil.toBoolean(
Strings.emptyToNull(properties.getProperty(AzureConstants.AZURE_CREATE_CONTAINER)), true);
org.apache.jackrabbit.oak.commons.StringUtils.emptyToNull(properties.getProperty(AzureConstants.AZURE_CREATE_CONTAINER)), true);
initAzureDSConfig();

concurrentRequestCount = PropertiesUtil.toInteger(
Expand All @@ -205,7 +205,7 @@ public void init() throws DataStoreException {
requestTimeout = PropertiesUtil.toInteger(properties.getProperty(AzureConstants.AZURE_BLOB_REQUEST_TIMEOUT), RetryPolicy.DEFAULT_CLIENT_RETRY_COUNT);
}
presignedDownloadURIVerifyExists = PropertiesUtil.toBoolean(
Strings.emptyToNull(properties.getProperty(AzureConstants.PRESIGNED_HTTP_DOWNLOAD_URI_VERIFY_EXISTS)), true);
org.apache.jackrabbit.oak.commons.StringUtils.emptyToNull(properties.getProperty(AzureConstants.PRESIGNED_HTTP_DOWNLOAD_URI_VERIFY_EXISTS)), true);

enableSecondaryLocation = PropertiesUtil.toBoolean(
properties.getProperty(AzureConstants.AZURE_BLOB_ENABLE_SECONDARY_LOCATION_NAME),
Expand Down Expand Up @@ -243,7 +243,7 @@ public void init() throws DataStoreException {

// Initialize reference key secret
boolean createRefSecretOnInit = PropertiesUtil.toBoolean(
Strings.emptyToNull(properties.getProperty(AzureConstants.AZURE_REF_ON_INIT)), true);
org.apache.jackrabbit.oak.commons.StringUtils.emptyToNull(properties.getProperty(AzureConstants.AZURE_REF_ON_INIT)), true);

if (createRefSecretOnInit) {
getOrCreateReferenceKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.apache.jackrabbit.oak.commons.conditions.Validate.checkArgument;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -108,4 +109,24 @@ public static int estimateMemoryUsage(String s) {
}
return (int) size;
}

/**
* Returns the string if it is not empty, or {@code null} otherwise.
*
* @param string the string to test and possibly return, may be {@code null}
* @return the input string if it is not empty, or {@code null} if the input string is {@code null} or empty
*/
public static String emptyToNull(@Nullable String string) {
return isNullOrEmpty(string) ? null : string;
}

/**
* Checks if a string is null or empty.
*
* @param string the string to check, may be {@code null}
* @return {@code true} if the string is null or empty, {@code false} otherwise
*/
static boolean isNullOrEmpty(@Nullable String string) {
return string == null || string.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Version("2.3.0")
@Version("2.4.0")
package org.apache.jackrabbit.oak.commons;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

/**
Expand Down Expand Up @@ -79,4 +80,55 @@ public void testEstimateMemoryUsage() {
}
}


@Test
public void testIsNullOrEmptyWithNull() {
Assert.assertTrue(StringUtils.isNullOrEmpty(null));
}

@Test
public void testIsNullOrEmptyWithEmptyString() {
Assert.assertTrue(StringUtils.isNullOrEmpty(""));
}

@Test
public void testIsNullOrEmptyWithNonEmptyString() {
Assert.assertFalse(StringUtils.isNullOrEmpty("not empty"));
}

@Test
public void testIsNullOrEmptyWithWhitespaceString() {
Assert.assertFalse(StringUtils.isNullOrEmpty(" "));
}

@Test
public void testIsNullOrEmptyWithNewlineString() {
Assert.assertFalse(StringUtils.isNullOrEmpty("\n"));
}

@Test
public void testEmptyToNullWithNull() {
Assert.assertNull(StringUtils.emptyToNull(null));
}

@Test
public void testEmptyToNullWithEmptyString() {
Assert.assertNull(StringUtils.emptyToNull(""));
}

@Test
public void testEmptyToNullWithNonEmptyString() {
Assert.assertEquals("not empty", StringUtils.emptyToNull("not empty"));
}

@Test
public void testEmptyToNullWithWhitespaceString() {
Assert.assertEquals(" ", StringUtils.emptyToNull(" "));
}

@Test
public void testEmptyToNullWithNewlineString() {
Assert.assertEquals("\n", StringUtils.emptyToNull("\n"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.memory.PropertyBuilder;
import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
Expand Down Expand Up @@ -587,7 +588,7 @@ private String getNodePath(@NotNull ACE principalBasedAce) throws RepositoryExce
if (v == null) {
throw new AccessControlException("Missing mandatory restriction rep:nodePath");
} else {
return getOakPath(Strings.emptyToNull(v.getString()));
return getOakPath(StringUtils.emptyToNull(v.getString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate;
import org.apache.jackrabbit.oak.security.authorization.ProviderCtx;
Expand Down Expand Up @@ -86,7 +87,7 @@ final class PermissionStoreEditor implements AccessControlConstants, PermissionC
if (isACE.test(ace)) {
boolean isAllow = isGrantACE.test(ace);
PrivilegeBits privilegeBits = bitsProvider.getBits(ace.getNames(REP_PRIVILEGES));
Set<Restriction> restrictions = restrictionProvider.readRestrictions(Strings.emptyToNull(accessControlledPath), providerCtx.getTreeProvider().createReadOnlyTree(ace));
Set<Restriction> restrictions = restrictionProvider.readRestrictions(StringUtils.emptyToNull(accessControlledPath), providerCtx.getTreeProvider().createReadOnlyTree(ace));

String principalName = Text.escapeIllegalJcrChars(ace.getString(REP_PRINCIPAL_NAME));
AcEntry entry = new AcEntry(principalName, index, isAllow, privilegeBits, restrictions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.conditions.Validate;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
Expand Down Expand Up @@ -142,7 +143,7 @@ public void initialize(NodeBuilder builder, String workspaceName) {
boolean omitPw = params.getConfigValue(PARAM_OMIT_ADMIN_PW, false);
userManager.createUser(adminId, (omitPw) ? null : adminId);
}
String anonymousId = Strings.emptyToNull(params.getConfigValue(PARAM_ANONYMOUS_ID, DEFAULT_ANONYMOUS_ID, String.class));
String anonymousId = StringUtils.emptyToNull(params.getConfigValue(PARAM_ANONYMOUS_ID, DEFAULT_ANONYMOUS_ID, String.class));
if (anonymousId != null && userManager.getAuthorizable(anonymousId) == null) {
userManager.createUser(anonymousId, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.jackrabbit.oak.api.ResultRow;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.security.user.DeclaredMembershipPredicate;
import org.apache.jackrabbit.oak.security.user.UserManagerImpl;
Expand Down Expand Up @@ -299,7 +300,7 @@ private static String getQueryPath(@NotNull String relPath) {
sb.append(segments[i]);
}
}
return Strings.emptyToNull(sb.toString());
return StringUtils.emptyToNull(sb.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.api.blob.BlobAccessProvider;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.fixture.SegmentTarFixture.SegmentTarFixtureBuilder;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreBuilder;
Expand Down Expand Up @@ -543,7 +544,7 @@ private void configurePersistentCache(DocumentNodeStoreBuilder<?> builder) {
Set<String> paths = new HashSet<>();
if (persistentCacheIncludes != null) {
for (String p : Splitter.on(',').split(persistentCacheIncludes)) {
p = p != null ? Strings.emptyToNull(p.trim()) : null;
p = p != null ? StringUtils.emptyToNull(p.trim()) : null;
if (p != null) {
paths.add(p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.run.cli.OptionsBean;
import org.apache.jackrabbit.oak.run.cli.OptionsBeanFactory;

Expand Down Expand Up @@ -254,7 +255,7 @@ private boolean anyActionSelected(){
private static List<String> trim(List<String> values) {
Set<String> paths = new HashSet<>();
for (String v : values) {
v = Strings.emptyToNull(v);
v = StringUtils.emptyToNull(v);
if (v != null) {
paths.add(v.trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.xml.parsers.DocumentBuilder;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.tika.exception.TikaException;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.ParseContext;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static void parseMimeTypes(Set<MediaType> result, NodeList mimes) {
Node mime = mimes.item(j);
if (mime instanceof Element) {
String mimeValue = mime.getTextContent();
mimeValue = Strings.emptyToNull(mimeValue);
mimeValue = StringUtils.emptyToNull(mimeValue);
if (mimeValue != null) {
MediaType mediaType = MediaType.parse(mimeValue.trim());
if (mediaType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ private Predicate<Path> createCachePredicate() {

Set<Path> paths = new HashSet<>();
for (String p : config.persistentCacheIncludes()) {
p = p != null ? Strings.emptyToNull(p.trim()) : null;
p = p != null ? org.apache.jackrabbit.oak.commons.StringUtils.emptyToNull(p.trim()) : null;
if (p != null) {
paths.add(Path.fromString(p));
}
Expand Down
Loading