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

fix: address PMD feedback #1

Open
wants to merge 1 commit into
base: jmarino/blake3_rebased
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ common --incompatible_disallow_empty_glob
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/bazel-buildfarm/issues/1479
common --noenable_bzlmod

# Support protobuf on macOS with Xcode 15.x
common:macos --host_cxxopt=-std=c++14 --cxxopt=-std=c++14
6 changes: 3 additions & 3 deletions src/main/java/build/buildfarm/common/blake3/Blake3Hasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public HashCode hash() {
}

@Override
public final Hasher putBoolean(boolean b) {
public Hasher putBoolean(boolean b) {
return putByte(b ? (byte) 1 : (byte) 0);
}

@Override
public final Hasher putDouble(double d) {
public Hasher putDouble(double d) {
return putLong(Double.doubleToRawLongBits(d));
}

@Override
public final Hasher putFloat(float f) {
public Hasher putFloat(float f) {
return putInt(Float.floatToRawIntBits(f));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package build.buildfarm.common.blake3;

import build.buildfarm.common.jni.JniLoader;
import java.nio.ByteBuffer;
import java.security.DigestException;
import java.security.MessageDigest;

Expand Down Expand Up @@ -55,11 +54,6 @@ public void engineUpdate(byte b) {
engineUpdate(oneByteArray, 0, 1);
}

@Override
public void engineUpdate(ByteBuffer input) {
super.engineUpdate(input);
}

private byte[] getOutput(int outputLength) {
byte[] retByteArray = new byte[outputLength];
blake3_hasher_finalize(hasher, retByteArray, outputLength);
Expand Down Expand Up @@ -102,12 +96,12 @@ public int engineDigest(byte[] buf, int off, int len) throws DigestException {
return digestBytes.length;
}

public static final native int hasher_size();
public static native int hasher_size();

public static final native void initialize_hasher(byte[] hasher);
public static native void initialize_hasher(byte[] hasher);

public static final native void blake3_hasher_update(
public static native void blake3_hasher_update(
byte[] hasher, byte[] input, int offset, int inputLen);

public static final native void blake3_hasher_finalize(byte[] hasher, byte[] out, int outLen);
public static native void blake3_hasher_finalize(byte[] hasher, byte[] out, int outLen);
}
8 changes: 5 additions & 3 deletions src/main/java/build/buildfarm/common/jni/JniLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.io.ByteStreams;
import com.google.devtools.build.lib.util.OS;
import build.buildfarm.common.os.OS;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -26,6 +26,7 @@
import java.nio.file.Path;

/** Generic code to interact with the platform-specific JNI code bundle. */
@SuppressWarnings("PMD.AvoidUsingNativeCode")
public final class JniLoader {

private static final boolean JNI_AVAILABLE;
Expand Down Expand Up @@ -109,7 +110,6 @@ private static void loadLibrary(String resourceName) throws IOException {
Files.delete(tempFile);
tempFile = null;
Files.delete(dir);
dir = null;
}
} catch (IOException e) {
try {
Expand All @@ -126,7 +126,9 @@ private static void loadLibrary(String resourceName) throws IOException {
}
}

protected JniLoader() {}
protected JniLoader() {
/* Don't construct me outside my package. */
}

/**
* Triggers the load of the JNI bundle in a platform-independent basis.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/build/buildfarm/common/os/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.util;
package build.buildfarm.common.os;

import java.util.EnumSet;

Expand Down