Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Swap from jsr305 to checker #49

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions checker-qual-shim/README.md
@@ -0,0 +1,4 @@
This is here purely to workaround https://github.com/typetools/checker-framework/issues/6420

We keep a compiletime-only copy of `DefaultQualifier`, with the only change being its @Retention, so that
usages of `DefaultQualifier` within util-core are kept in the compiled jar.
9 changes: 9 additions & 0 deletions checker-qual-shim/build.gradle
@@ -0,0 +1,9 @@
plugins {
id 'java'
}

dependencies {
compileOnly libs.checkerQual
}

indeedOss.activateFeature 'java'
@@ -0,0 +1,111 @@
/**
* Checker Framework qualifiers Copyright 2004-present by the Checker Framework developers
*
* <p>MIT License:
*
* <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.checkerframework.framework.qual;

import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Applied to a declaration of a package, type, method, variable, etc., specifies that the given
* annotation should be the default. The default is applied to type uses within the declaration for
* which no other annotation is explicitly written. (The default is not applied to the "parametric
* locations": class declarations, type parameter declarations, and type parameter uses.) If
* multiple {@code DefaultQualifier} annotations are in scope, the innermost one takes precedence.
* DefaultQualifier takes precedence over {@link DefaultQualifierInHierarchy}.
*
* <p>You may write multiple {@code @DefaultQualifier} annotations (for unrelated type systems, or
* with different {@code locations} fields) at the same location. For example:
*
* <pre>
* &nbsp; @DefaultQualifier(NonNull.class)
* &nbsp; @DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.IMPLICIT_UPPER_BOUND)
* &nbsp; @DefaultQualifier(Tainted.class)
* &nbsp; class MyClass { ... }
* </pre>
*
* <p>This annotation currently has no effect in stub files.
*
* @see org.checkerframework.framework.qual.TypeUseLocation
* @see DefaultQualifierInHierarchy
* @see DefaultFor
* @checker_framework.manual #defaults Default qualifier for unannotated types
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.PACKAGE,
ElementType.TYPE,
ElementType.CONSTRUCTOR,
ElementType.METHOD,
ElementType.FIELD,
ElementType.LOCAL_VARIABLE,
ElementType.PARAMETER
})
@Repeatable(DefaultQualifier.List.class)
public @interface DefaultQualifier {

/**
* The Class for the default annotation.
*
* <p>To prevent affecting other type systems, always specify an annotation in your own type
* hierarchy. (For example, do not set {@link
* org.checkerframework.common.subtyping.qual.Unqualified} as the default.)
*/
Class<? extends Annotation> value();

/**
* Returns the locations to which the annotation should be applied.
*
* @return the locations to which the annotation should be applied
*/
TypeUseLocation[] locations() default {TypeUseLocation.ALL};

/**
* A wrapper annotation that makes the {@link DefaultQualifier} annotation repeatable.
*
* <p>Programmers generally do not need to write this. It is created by Java when a programmer
* writes more than one {@link DefaultQualifier} annotation at the same location.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.PACKAGE,
ElementType.TYPE,
ElementType.CONSTRUCTOR,
ElementType.METHOD,
ElementType.FIELD,
ElementType.LOCAL_VARIABLE,
ElementType.PARAMETER
})
public static @interface List {
/**
* Return the repeatable annotations.
*
* @return the repeatable annotations
*/
DefaultQualifier[] value();
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Expand Up @@ -2,9 +2,9 @@
slf4jApi = "org.slf4j:slf4j-api:1.7.32"
junit = "junit:junit:4.8.2"
guava = "com.google.guava:guava:20.0"
jsr305 = "com.google.code.findbugs:jsr305:1.3.9"
servletApi = "org.apache.tomcat:tomcat-servlet-api:7.0.8"
freemarker = "org.freemarker:freemarker:2.3.16"
easymock = "org.easymock:easymock:4.1"
commonsLang = "commons-lang:commons-lang:2.6"
hamcrest = "org.hamcrest:hamcrest-core:2.2"
checkerQual = "org.checkerframework:checker-qual:3.42.0"
3 changes: 1 addition & 2 deletions io/build.gradle
Expand Up @@ -6,13 +6,12 @@ dependencies {
implementation project(':util-core')
implementation libs.guava
implementation libs.slf4jApi
api libs.checkerQual

// This is a fake copy of the log4j1 Logger, which allows us to continue
// accepting it in our deprecated method signatures without accidentially using
// any of its functionality.
compileOnly project(':log4j1dummyshim')

compileOnly libs.jsr305

testImplementation libs.junit
}
10 changes: 4 additions & 6 deletions io/src/main/java/com/indeed/util/io/Directories.java
Expand Up @@ -2,9 +2,8 @@
package com.indeed.util.io;

import com.google.common.collect.Iterables;
import org.checkerframework.checker.nullness.qual.NonNull;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;
Expand All @@ -26,8 +25,7 @@ public final class Directories {
* @return number of inodes under it.
* @throws IOException
*/
@Nonnegative
public static int count(@Nonnull final Path dir) throws IOException {
public static int count(@NonNull final Path dir) throws IOException {
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
return Iterables.size(stream);
} catch (DirectoryIteratorException ex) {
Expand All @@ -48,8 +46,8 @@ public static int count(@Nonnull final Path dir) throws IOException {
* @return all files in that directory
* @throws IOException
*/
@Nonnull
public static List<Path> list(@Nonnull final Path dir) throws IOException {
@NonNull
public static List<Path> list(@NonNull final Path dir) throws IOException {
final List<Path> contents = new ArrayList<>();
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (final Path entry : stream) {
Expand Down
62 changes: 31 additions & 31 deletions io/src/main/java/com/indeed/util/io/Files.java
Expand Up @@ -5,10 +5,10 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.hash.Hashing;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
Expand Down Expand Up @@ -67,7 +67,7 @@ public static String buildPath(String... parts) {
* be written, flushed, synced, or closed
*/
public static void writeObjectToFileOrDie2(
@Nonnull final Object obj, @Nonnull final String file) throws IOException {
@NonNull final Object obj, @NonNull final String file) throws IOException {
Preconditions.checkNotNull(file, "file argument is required!");
Preconditions.checkArgument(!file.isEmpty(), "file argument is required!");

Expand Down Expand Up @@ -106,18 +106,18 @@ public static void writeObjectToFileOrDie2(
/** @deprecated Use {@link #writeObjectToFileOrDie2(java.lang.Object, java.lang.String)} */
@Deprecated
public static void writeObjectToFileOrDie(
@Nonnull final Object obj,
@Nonnull final String file,
@Nonnull final org.apache.log4j.Logger log)
@NonNull final Object obj,
@NonNull final String file,
final org.apache.log4j.@NonNull Logger log)
throws IOException {
writeObjectToFileOrDie2(obj, file);
}

private static class ObjectOutputStreamCallback implements OutputStreamCallback {
private long checksumForWrittenData = 0L;
@Nonnull private final Object obj;
@NonNull private final Object obj;

private ObjectOutputStreamCallback(@Nonnull Object obj) {
private ObjectOutputStreamCallback(@NonNull Object obj) {
this.obj = obj;
}

Expand All @@ -126,7 +126,7 @@ public long getChecksumValue() {
}

@Override
public void writeAndFlushData(@Nonnull OutputStream outputStream) throws IOException {
public void writeAndFlushData(@NonNull OutputStream outputStream) throws IOException {
final ChecksummingOutputStream checksummingOutputStream =
new ChecksummingOutputStream(new BufferedOutputStream(outputStream));
final ObjectOutputStream out = new ObjectOutputStream(checksummingOutputStream);
Expand All @@ -141,7 +141,7 @@ public void writeAndFlushData(@Nonnull OutputStream outputStream) throws IOExcep
}

private static class ChecksummingOutputStream extends FilterOutputStream {
@Nonnull private final Checksum checksummer;
@NonNull private final Checksum checksummer;

private ChecksummingOutputStream(OutputStream out) {
super(out);
Expand Down Expand Up @@ -177,13 +177,13 @@ public long getChecksumValue() {
}

private static interface OutputStreamCallback {
void writeAndFlushData(@Nonnull final OutputStream outputStream) throws IOException;
void writeAndFlushData(@NonNull final OutputStream outputStream) throws IOException;
}

// return a reference to a temp file that contains the written + flushed + fsynced + closed data
@Nonnull
@NonNull
private static File writeDataToTempFileOrDie2(
@Nonnull final OutputStreamCallback callback, @Nonnull final File targetFile)
@NonNull final OutputStreamCallback callback, @NonNull final File targetFile)
throws IOException {
Preconditions.checkNotNull(callback, "callback argument is required!");
Preconditions.checkNotNull(targetFile, "targetFile argument is required!");
Expand Down Expand Up @@ -229,18 +229,18 @@ private static File writeDataToTempFileOrDie2(
* java.io.File)}
*/
@Deprecated
@Nonnull
@NonNull
private static File writeDataToTempFileOrDie(
@Nonnull final OutputStreamCallback callback,
@Nonnull final File targetFile,
@Nonnull final org.apache.log4j.Logger log)
@NonNull final OutputStreamCallback callback,
@NonNull final File targetFile,
final org.apache.log4j.@NonNull Logger log)
throws IOException {
return writeDataToTempFileOrDie2(callback, targetFile);
}

@Nonnull
@NonNull
private static File writeTextToTempFileOrDie2(
@Nonnull final String[] text, @Nonnull final File targetFile) throws IOException {
@NonNull final String[] text, @NonNull final File targetFile) throws IOException {
Preconditions.checkNotNull(text, "callback argument is required!");
Preconditions.checkNotNull(targetFile, "targetFile argument is required!");

Expand Down Expand Up @@ -275,11 +275,11 @@ private static File writeTextToTempFileOrDie2(

/** @deprecated Use {@link #writeTextToTempFileOrDie2(java.lang.String[], java.io.File)} */
@Deprecated
@Nonnull
@NonNull
private static File writeTextToTempFileOrDie(
@Nonnull final String[] text,
@Nonnull final File targetFile,
@Nonnull final org.apache.log4j.Logger log)
@NonNull final String[] text,
@NonNull final File targetFile,
final org.apache.log4j.@NonNull Logger log)
throws IOException {
return writeTextToTempFileOrDie2(text, targetFile);
}
Expand All @@ -297,7 +297,7 @@ private static File writeTextToTempFileOrDie(
* synced, or closed
*/
public static boolean writeObjectIfChangedOrDie2(
@Nonnull final Object obj, @Nonnull final String file) throws IOException {
@NonNull final Object obj, @NonNull final String file) throws IOException {
Preconditions.checkNotNull(file, "file argument is required!");
Preconditions.checkArgument(!file.isEmpty(), "file argument is required!");

Expand Down Expand Up @@ -364,15 +364,15 @@ public static boolean writeObjectIfChangedOrDie2(
/** @deprecated Use {@link #writeObjectIfChangedOrDie2(java.lang.Object, java.lang.String)} */
@Deprecated
public static boolean writeObjectIfChangedOrDie(
@Nonnull final Object obj,
@Nonnull final String file,
@Nonnull final org.apache.log4j.Logger log)
@NonNull final Object obj,
@NonNull final String file,
final org.apache.log4j.@NonNull Logger log)
throws IOException {
return writeObjectIfChangedOrDie2(obj, file);
}

public static long computeFileChecksum(
@Nonnull final File file, @Nonnull final Checksum checksum) throws IOException {
@NonNull final File file, @NonNull final Checksum checksum) throws IOException {
return com.google.common.io.Files.asByteSource(file).hash(Hashing.crc32()).padToLong();
}

Expand Down Expand Up @@ -694,7 +694,7 @@ public static void writeToTextFile(String[] lines, String file) {
}

public static void writeToTextFileOrDie(
@Nonnull final String[] lines, @Nonnull final String file) throws IOException {
@NonNull final String[] lines, @NonNull final String file) throws IOException {
// Write out a temp file (or die)
final File f = new File(file);
final File temp = writeTextToTempFileOrDie2(lines, f);
Expand Down Expand Up @@ -778,7 +778,7 @@ public static boolean delete(String file) {
* @return true if all deletions were successful, false if file did not exist
* @throws IOException if deletion fails and the file still exists at the end
*/
public static boolean deleteOrDie(@Nonnull final String file) throws IOException {
public static boolean deleteOrDie(@NonNull final String file) throws IOException {
// this returns true if the file was actually deleted
// and false for 2 cases:
// 1. file did not exist to start with
Expand Down Expand Up @@ -893,8 +893,8 @@ public static String getFileHash(final String file, final String algorithm)
* Converts a byte array to a hex string. The String returned will be of length exactly {@code
* bytes.length * 2}.
*/
@Nonnull
public static String toHex(@Nonnull final byte[] bytes) {
@NonNull
public static String toHex(@NonNull final byte[] bytes) {
StringBuilder buf = new StringBuilder(bytes.length * 2);
for (byte b : bytes) {
String hexDigits = Integer.toHexString((int) b & 0x00ff);
Expand Down