Skip to content

Commit

Permalink
Enable semantic checking for @MustBeClosed with RefCounted holders an…
Browse files Browse the repository at this point in the history
…d streams

Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Apr 23, 2024
1 parent 103c6a0 commit 06d0417
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions TrafficCapture/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ allprojects {
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'

// TODO: Expand to do more static checking in more projects
if (project.name == "trafficReplayer" || project.name == "trafficCaptureProxyServer") {
dependencies {
annotationProcessor group: 'com.google.errorprone', name: 'error_prone_core', version: '2.26.1'
}
tasks.named('compileJava', JavaCompile) {
if (project.name == "trafficReplayer" || project.name == "trafficCaptureProxyServer") {
options.compilerArgs += [
"-XDcompilePolicy=simple",
"-Xplugin:ErrorProne -XepDisableAllChecks -Xep:MustBeClosed:ERROR -XepDisableWarningsInGeneratedCode",
]
}
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package org.opensearch.migrations.replay.util;

import com.google.errorprone.annotations.MustBeClosed;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.Collection;

import java.util.stream.Stream;

public final class NettyUtils {
@MustBeClosed
public static Stream<ByteBuf> createCloseableByteBufStream(Stream<byte[]> byteArrStream) {
return RefSafeStreamUtils.refSafeMap(byteArrStream, Unpooled::wrappedBuffer);
}

@MustBeClosed
public static Stream<ByteBuf> createCloseableByteBufStream(Collection<byte[]> byteArrCollection) {
return createCloseableByteBufStream(byteArrCollection.stream());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opensearch.migrations.replay.util;

import com.google.errorprone.annotations.MustBeClosed;
import io.netty.util.ReferenceCountUtil;
import javax.annotation.Nullable;

Expand All @@ -10,6 +11,7 @@ private RefSafeHolder(@Nullable T resource) {
this.resource = resource;
}

@MustBeClosed
static public <T> RefSafeHolder<T> create(@Nullable T resource) {
return new RefSafeHolder<>(resource);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.opensearch.migrations.replay.util;

import com.google.errorprone.annotations.MustBeClosed;
import io.netty.util.ReferenceCounted;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.function.Function;
import java.util.stream.Stream;

public final class RefSafeStreamUtils {
@MustBeClosed
public static <T, R extends ReferenceCounted> Stream<R> refSafeMap(Stream<T> inputStream,
Function<T, R> referenceTrackedMappingFunction) {
final Deque<R> refCountedTracker = new ArrayDeque<>();
Expand Down

0 comments on commit 06d0417

Please sign in to comment.