Skip to content
Draft
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
22 changes: 21 additions & 1 deletion fdb-record-layer-icu/fdb-record-layer-icu.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@
* limitations under the License.
*/

plugins {
alias(libs.plugins.errorprone)
}

def coreProject = ":${ext.coreProjectName}"
dependencies {
api project(coreProject)
implementation(libs.icu)
implementation(libs.protobuf)
implementation(libs.slf4j.api)
compileOnly(libs.jsr305)
compileOnly(libs.jspecify)
compileOnly(libs.autoService)
annotationProcessor(libs.autoService)

errorprone(libs.errorprone.core)
errorprone(libs.nullaway)

testImplementation project(':fdb-test-utils')
testImplementation(testFixtures(project(coreProject)))
testImplementation(libs.bundles.test.impl)
Expand All @@ -36,6 +43,19 @@ dependencies {
testImplementation(libs.snakeyaml)
}

// jspecify + NullAway, scoped to this module only. See the @NullMarked package-info.java in
// com.apple.foundationdb.record.icu. Part of a module-by-module null-checking rollout that started
// with fdb-relational-grpc and fdb-relational-jdbc.
tasks.withType(JavaCompile).configureEach {
options.errorprone {
disableAllChecks = true
error("NullAway")
option("NullAway:AnnotatedPackages", "com.apple.foundationdb.record.icu")
option("NullAway:JSpecifyMode", "true")
option("NullAway:AcknowledgeRestrictiveAnnotations", "true")
}
}

apply from: rootProject.file('gradle/publishing.gradle')
publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.apple.foundationdb.record.metadata.expressions.KeyExpression;
import com.google.auto.service.AutoService;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;

Expand All @@ -40,15 +39,14 @@
public class CollateFunctionKeyExpressionFactoryICU implements FunctionKeyExpression.Factory {
public static final String FUNCTION_NAME = "collate_icu";

@Nonnull
@Override
public List<FunctionKeyExpression.Builder> getBuilders() {
return Collections.singletonList(
new FunctionKeyExpression.BiFunctionBuilder(FUNCTION_NAME, CollateFunctionKeyExpressionICU::new));
}

protected static class CollateFunctionKeyExpressionICU extends CollateFunctionKeyExpression {

Check notice on line 48 in fdb-record-layer-icu/src/main/java/com/apple/foundationdb/record/icu/CollateFunctionKeyExpressionFactoryICU.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 100.0% (4/4 lines) | Changed lines: N/A (no executable lines)
protected CollateFunctionKeyExpressionICU(@Nonnull String name, @Nonnull KeyExpression arguments) {
protected CollateFunctionKeyExpressionICU(String name, KeyExpression arguments) {
super(TextCollatorRegistryICU.instance(), name, arguments);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.ibm.icu.text.Collator;
import com.ibm.icu.util.ULocale;

import javax.annotation.Nonnull;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -59,21 +58,18 @@
private TextCollatorRegistryICU() {
}

@Nonnull
@Override
public String getName() {
return "icu";
}

@Override
@Nonnull
public TextCollator getTextCollator(int strength) {
return getTextCollator(DEFAULT_LOCALE, strength);
}

@Override

Check notice on line 71 in fdb-record-layer-icu/src/main/java/com/apple/foundationdb/record/icu/TextCollatorRegistryICU.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 100.0% (18/18 lines) | Changed lines: 100.0% (1/1 lines)
@Nonnull
public TextCollator getTextCollator(@Nonnull String locale, int strength) {
public TextCollator getTextCollator(String locale, int strength) {
return MapUtils.computeIfAbsent(collators, NonnullPair.of(locale, strength), key -> {
final Collator collator = DEFAULT_LOCALE.equals(locale) ?
Collator.getInstance(ULocale.forLocale(Locale.ROOT)) :
Expand All @@ -84,21 +80,19 @@
}

protected static class TextCollatorICU implements TextCollator {
@Nonnull
private final Collator collator;
protected TextCollatorICU(@Nonnull Collator collator) {

protected TextCollatorICU(Collator collator) {
this.collator = collator;
}

@Override
public int compare(@Nonnull String str1, @Nonnull String str2) {
public int compare(String str1, String str2) {
return collator.compare(str1, str2);
}

@Nonnull
@Override
public ByteString getKey(@Nonnull String str) {
public ByteString getKey(String str) {
return ZeroCopyByteString.wrap(collator.getCollationKey(str).toByteArray());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
/**
* Use ICU4J instead of JRE {@code Collator} classes.
*/
@NullMarked
package com.apple.foundationdb.record.icu;

import org.jspecify.annotations.NullMarked;
Loading