You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "mxtymoshyk (via GitHub)" <gi...@apache.org> on 2026/09/04 04:23:55 UTC

[PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

mxtymoshyk opened a new pull request, #40008:
URL: https://github.com/apache/beam/pull/40008

   Part of #35312.
   
   The global SpotBugs filter suppressed `CT_CONSTRUCTOR_THROW` in every module, so a constructor that throws after publishing `this` was never reported anywhere. This deletes those three filter lines and fixes everything the detector then found.
   
   I used two fixes. Where the class is not public, I marked it `final`. SpotBugs' `ConstructorThrow` detector returns early on a final class, so the warning goes away because the problem is gone: a finalizer attack needs an attacker-supplied subclass, and a final class cannot have one. Every other class gets a `@SuppressFBWarnings` whose justification says why it has to stay extensible.
   
   A class was made `final` only when it is neither abstract nor public. Code outside the repo can subclass a package-private class only by declaring itself inside a Beam package, which is unsupported and breaks under shaded jars, so sealing it cannot break a downstream user.
   
   Public classes annotated `@Internal` get the suppression as well. `@Internal` withdraws the compatibility guarantee, but the class is still reachable, so a forked runner may already extend it and sealing it would break that fork at compile time. Six classes fall in this category: `BoundedTrieData`, `ExplicitShardedFile`, `PCollectionViews.SingletonViewFn`, `PCollectionViews.SingletonViewFn2`, `FnApiDoFnRunner`, and `SplittableSplitAndSizeRestrictionsDoFnRunner`.
   
   I also checked that nothing in the repo extends any class I sealed. That check only proves the tree still compiles. It is not by itself a reason to seal a class, and it says nothing about out-of-tree code.
   
   Verified locally with `./gradlew spotbugsMain spotlessJavaCheck --continue`: 140 modules pass `spotbugsMain`, 190 pass `spotlessJavaCheck`, and no report contains a `CT_CONSTRUCTOR_THROW` finding.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/actions/workflows/build_wheels.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/actions/workflows/python_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/actions/workflows/java_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/actions/workflows/go_tests.yml/badge.svg?event=schedule&&?branch=master)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-6044994832

   I won't try to re-run the tests to get them green since you'll need to rebase to resolve merge conflicts anyhow.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on code in PR #40008:
URL: https://github.com/apache/beam/pull/40008#discussion_r4186011977


##########
examples/java/src/main/java/org/apache/beam/examples/subprocess/utils/ExecutableFile.java:
##########
@@ -26,6 +27,11 @@
 @SuppressWarnings({
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should be `final`.



##########
it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/bigtable/BigtableResourceManager.java:
##########
@@ -77,6 +78,11 @@
  *
  * <p>The class is thread-safe.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/BoundedTrieData.java:
##########
@@ -57,8 +57,12 @@
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
 @SuppressFBWarnings(
-    value = "IS2_INCONSISTENT_SYNC",
-    justification = "Some access on purpose are left unsynchronized")
+    value = {"IS2_INCONSISTENT_SYNC", "CT_CONSTRUCTOR_THROW"},
+    justification =
+        "Some access on purpose are left unsynchronized."
+            + " Public, so it cannot be made final despite @Internal."
+            + " Out-of-tree code such as a forked runner may already subclass it."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/2.0/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/io/UnboundedSourceWrapper.java:
##########
@@ -67,6 +68,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/io/source/LazyFlinkSourceSplitEnumerator.java:
##########
@@ -34,6 +35,11 @@
 import org.slf4j.LoggerFactory;
 
 /** Splits a bounded Beam source and assigns one split for each reader request. */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/FlinkStreamingPortablePipelineTranslator.java:
##########
@@ -130,6 +131,11 @@
   "keyfor",
   "nullness"
 }) // TODO(https://github.com/apache/beam/issues/20497)
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
it/clickhouse/src/main/java/org/apache/beam/it/clickhouse/ClickHouseResourceManager.java:
##########
@@ -44,6 +45,11 @@
  *
  * <p>The class is thread-safe.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/io/UnboundedSourceWrapper.java:
##########
@@ -66,6 +67,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/metrics/sink/CsvSink.java:
##########
@@ -36,6 +37,11 @@
  * "spark.metrics.conf.*.sink.csv.unit"=seconds
  * }</pre>
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/metrics/SparkBeamMetricSource.java:
##########
@@ -18,12 +18,18 @@
 package org.apache.beam.runners.spark.metrics;
 
 import com.codahale.metrics.MetricRegistry;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import org.apache.spark.metrics.source.Source;
 
 /**
  * A Spark {@link Source} that is tailored to expose a {@link SparkBeamMetric}, wrapping an
  * underlying {@link org.apache.beam.sdk.metrics.MetricResults} instance.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/metrics/sink/CodahaleCsvSink.java:
##########
@@ -36,6 +37,11 @@
  * "spark.metrics.conf.*.sink.csv.unit"=seconds
  * }</pre>
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/metrics/sink/GraphiteSink.java:
##########
@@ -39,6 +40,11 @@
  * "spark.metrics.conf.*.sink.graphite.regex"="<optional_regex_to_send_matching_metrics>"
  * }</pre>
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/jmh/src/main/java/org/apache/beam/sdk/jmh/schemas/RowBundle.java:
##########
@@ -54,6 +55,11 @@
  * adequately timestamped without risking generating wrong results.
  */
 @State(Scope.Benchmark)
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Subclassed inside Beam, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   The jmh folder is just our own benchmarks (and TBH not the main ones we look at much). These can be tweaked in breaking ways also.
   
   This class in particular would benefit from a refactor so the throwing can happen in a static factory method, and then "just data" passed to the constructor.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/transforms/providers/JavaRowUdf.java:
##########
@@ -58,6 +58,11 @@
 import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
 import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.io.ByteStreams;
 
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   Definitely not meant for subclassing



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/join/CoGbkResult.java:
##########
@@ -55,6 +56,11 @@
 @SuppressWarnings({
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one is also only meant to be consumed by users, not extended or produced. Nonetheless it might be extended somewhere out the wild.



##########
examples/java/src/main/java/org/apache/beam/examples/subprocess/utils/CallingSubProcessUtils.java:
##########
@@ -88,6 +89,11 @@ private static void releaseSemaphore(String binaryName) throws IllegalStateExcep
   }
 
   /** Permit class for access to worker cpu resources. */
+  @SuppressFBWarnings(
+      value = "CT_CONSTRUCTOR_THROW",
+      justification =
+          "Public API, so it cannot be made final."
+              + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should be `final`.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/ExplicitShardedFile.java:
##########
@@ -38,6 +39,12 @@
 
 /** A sharded file where the file names are simply provided. */
 @Internal
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public, so it cannot be made final despite @Internal."
+            + " Out-of-tree code such as a forked runner may already subclass it."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   the whole `util` folder is not public



##########
it/splunk/src/main/java/org/apache/beam/it/splunk/SplunkResourceManager.java:
##########
@@ -60,6 +61,11 @@
  * <p>Note: The Splunk TestContainer will only run on M1 Mac's if the Docker version is >= 4.16.0
  * and the "Use Rosetta for x86/amd64 emulation on Apple Silicon" setting is enabled.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/2.0/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/state/FlinkStateInternals.java:
##########
@@ -103,6 +104,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/core-java/src/main/java/org/apache/beam/runners/core/construction/SerializablePipelineOptions.java:
##########
@@ -32,6 +33,11 @@
  * Holds a {@link PipelineOptions} in JSON serialized form and calls {@link
  * FileSystems#setDefaultPipelineOptions(PipelineOptions)} on construction or on deserialization.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/graph/QueryablePipeline.java:
##########
@@ -56,6 +57,11 @@
  * other.
  */
 @SuppressWarnings({"nullness", "keyfor"}) // TODO(https://github.com/apache/beam/issues/20497)
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API for runner authors, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   the whole `util` folder is not public



##########
examples/java/src/main/java/org/apache/beam/examples/complete/datatokenization/utils/SchemasUtils.java:
##########
@@ -53,6 +54,11 @@
   "argument",
   "return"
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should be `final`.



##########
runners/flink/2.0/src/main/java/org/apache/beam/runners/flink/FlinkStreamingPortablePipelineTranslator.java:
##########
@@ -130,6 +131,11 @@
   "keyfor",
   "nullness"
 }) // TODO(https://github.com/apache/beam/issues/20497)
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/core-java/src/main/java/org/apache/beam/runners/core/StatefulDoFnRunner.java:
##########
@@ -59,6 +60,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   Note that _everything_ under the "runners" folder is non-public.
   
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionViews.java:
##########
@@ -473,6 +474,12 @@ public static Map<TupleTag<?>, PValue> toAdditionalInputs(Iterable<PCollectionVi
    * <p>{@link SingletonViewFn} is meant to be removed in the future and replaced with this class.
    */
   @Internal
+  @SuppressFBWarnings(
+      value = "CT_CONSTRUCTOR_THROW",
+      justification =
+          "Public, so it cannot be made final despite @Internal."
+              + " Out-of-tree code such as a forked runner may already subclass it."
+              + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   the whole `util` folder is not public



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/io/source/FlinkSourceSplitEnumerator.java:
##########
@@ -39,6 +40,11 @@
 import org.slf4j.LoggerFactory;
 
 /** Splits a Beam source and assigns its splits to Flink source readers round-robin. */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/stableinput/KeyedBufferingElementsHandler.java:
##########
@@ -31,6 +32,11 @@
 @SuppressWarnings({
   "rawtypes" // TODO(https://github.com/apache/beam/issues/20447)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/stableinput/BufferingDoFnRunner.java:
##########
@@ -55,6 +56,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactory.java:
##########
@@ -96,6 +97,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/jet/src/main/java/org/apache/beam/runners/jet/JetRunner.java:
##########
@@ -47,6 +48,11 @@
 import org.slf4j.LoggerFactory;
 
 /** Jet specific implementation of Beam's {@link PipelineRunner}. */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/flink/src/main/java/org/apache/beam/runners/flink/translation/wrappers/streaming/state/FlinkStateInternals.java:
##########
@@ -103,6 +104,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/jet/src/main/java/org/apache/beam/runners/jet/processors/AssignWindowP.java:
##########
@@ -43,6 +44,11 @@
   "nullness",
   "keyfor"
 }) // TODO(https://github.com/apache/beam/issues/20497)
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/metrics/sink/CodahaleGraphiteSink.java:
##########
@@ -39,6 +40,11 @@
  * "spark.metrics.conf.*.sink.graphite.regex"="<optional_regex_to_send_matching_metrics>"
  * }</pre>
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/translation/SparkDatasetPortablePipelineTranslator.java:
##########
@@ -81,6 +82,11 @@
   "unchecked",
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/translation/SparkBatchPortablePipelineTranslator.java:
##########
@@ -77,6 +78,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/structuredstreaming/metrics/SparkBeamMetricSource.java:
##########
@@ -18,12 +18,18 @@
 package org.apache.beam.runners.spark.structuredstreaming.metrics;
 
 import com.codahale.metrics.MetricRegistry;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import org.apache.spark.metrics.source.Source;
 
 /**
  * A Spark {@link Source} that is tailored to expose a {@link SparkBeamMetric}, wrapping an
  * underlying {@link org.apache.beam.sdk.metrics.MetricResults} instance.
  */
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/io/CompressedSource.java:
##########
@@ -65,6 +66,11 @@
 @SuppressWarnings({
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one is public, but very unlikely to be subclasses, and the private constructor can not be invoked. So it is safe to change it to a factory method that would throw the exception.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/fn/data/BeamFnDataOutboundAggregator.java:
##########
@@ -61,6 +62,11 @@
 // create another memory barrier. Also note that flush is always invoked when synchronizing on
 // flushLock when there is a periodic flushing thread.
 @NotThreadSafe
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Subclassed inside Beam, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   Everything in the `fn` directory is also not public API and can be changed and refactored to fix it, e.g. with a static factory method.



##########
runners/spark/src/main/java/org/apache/beam/runners/spark/translation/SparkStreamingPortablePipelineTranslator.java:
##########
@@ -72,6 +73,11 @@
   "rawtypes", // TODO(https://github.com/apache/beam/issues/20447)
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java:
##########
@@ -69,6 +70,11 @@ private static class SchemaInformationProviders {
   private static final Object lock = new Object();
 
   /** Return value after converting a schema. */
+  @SuppressFBWarnings(
+      value = "CT_CONSTRUCTOR_THROW",
+      justification =
+          "Public API, so it cannot be made final."
+              + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   anything in a directory like 'util' or 'utils' is meant to not be public. Certainly not this class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Sample.java:
##########
@@ -291,6 +292,11 @@ public T extractOutput(List<T> accumulator) {
    *
    * @param <T> the type of the elements
    */
+  @SuppressFBWarnings(
+      value = "CT_CONSTRUCTOR_THROW",
+      justification =
+          "Public API, so it cannot be made final."
+              + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   This one can/should (probably) be `final`. I didn't actually check if anything extends it, but it does not appear to be a deliberate base class or interface class.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/DefaultArtifactResolver.java:
##########
@@ -37,6 +38,11 @@
 @SuppressWarnings({
   "nullness" // TODO(https://github.com/apache/beam/issues/20497)
 })
+@SuppressFBWarnings(
+    value = "CT_CONSTRUCTOR_THROW",
+    justification =
+        "Public API for runner authors, so it cannot be made final."
+            + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   the whole `util` folder is not public



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionViews.java:
##########
@@ -574,6 +581,12 @@ public interface IsSingletonView<T> {}
    * @deprecated See {@link SingletonViewFn2}.
    */
   @Deprecated
+  @SuppressFBWarnings(
+      value = "CT_CONSTRUCTOR_THROW",
+      justification =
+          "Public, so it cannot be made final despite @Internal."
+              + " Out-of-tree code such as a forked runner may already subclass it."
+              + " A finalizer attack needs an attacker-supplied subclass on the classpath.")

Review Comment:
   the whole `util` folder is not public



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "mxtymoshyk (via GitHub)" <gi...@apache.org>.
mxtymoshyk commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-6002187656

   @kennknowles thanks for the review. I took the quick route you suggested: suppress every finding and drop the global filter.
   
   All 87 suppressions this PR adds now share one justification: "Pre-existing finding, not triaged yet. Making the class final or moving the throwing code into a static factory method may fix it." The old text said each class could not be made final, and as your comments show, that was wrong for most of them. The 45 classes the PR already made final stay final (82b08fc).
   
   I'll do the categorization in follow-up PRs, using the groups from your review:
   
   - Classes that aren't public API because of where they live: `runners/`, `examples/`, `it/`, the harness, and the `util`, `fn` and `construction` packages. That's 43 of the 87 and covers most of your inline comments. I'll make them final after checking that nothing subclasses or mocks them.
   - Refactors to static factory methods, starting with `CompressedSource`, `BeamFnDataOutboundAggregator` and `RowBundle`.
   - Public classes such as `FixedWindows`, `SlidingWindows` and `CoGbkResult`, where `final` is a judgment call. I'd like your read on those before I change them.
   - Abstract classes, classes subclassed inside Beam (`SimpleFunction`, `TypeDescriptor`) and classes mocked with Mockito. These keep their suppressions.
   
   I'll leave your inline comments open until the follow-up that addresses each one lands.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5536857338

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5998387435

   Something we can do right away, to prevent introducing more failures:
   
    - Suppress every place where there is a failure
    - Remove the global suppression
   
   Doing this is fine, but I don't want to do it with the existing comments on the suppressions, because those comments may make future editors think they cannot change things that actually they can.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5838909072

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/40008?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 58.56%. Comparing base ([`7203268`](https://app.codecov.io/gh/apache/beam/commit/720326829a71b16b3553a246305fbf9031a70d3d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`874160d`](https://app.codecov.io/gh/apache/beam/commit/874160deffbf46b1cb65915b99b6c57dff80cc85?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 13 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #40008      +/-   ##
   ============================================
   + Coverage     56.14%   58.56%   +2.41%     
   - Complexity     2288    13727   +11439     
   ============================================
     Files          1121     2579    +1458     
     Lines        177151   270048   +92897     
     Branches       1488    11162    +9674     
   ============================================
   + Hits          99466   158148   +58682     
   - Misses        75161   105903   +30742     
   - Partials       2524     5997    +3473     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/beam/pull/40008/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [java](https://app.codecov.io/gh/apache/beam/pull/40008/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `64.86% <100.00%> (-10.87%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/beam/pull/40008?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5998078228

   Interesting! I'll take a look. Most of the time, classes that are not explicitly meant to be base classes / interfaces should be `final`, so that is actually a great fix to apply almost all the time. Java just makes it non-default so it is a bit annoying.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "kennknowles (via GitHub)" <gi...@apache.org>.
kennknowles merged PR #40008:
URL: https://github.com/apache/beam/pull/40008


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "mxtymoshyk (via GitHub)" <gi...@apache.org>.
mxtymoshyk commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-6045569068

   @kennknowles thanks for approving. I rebased onto master (b673ddd) and fixed the conflict in `GcsUtilV2` with #40376. The conflict was two import lines. The PR diff hasn't changed otherwise. SpotBugs passes locally on gcp-core, the module that had the conflict, and CI is running again. Once it's green this is ready to merge.
   
   The `GCP_IO_Direct_OtherGCP` failure on the previous run came from two `SpannerChangeStreamPlacementTableIT` tests that hit `DEADLINE_EXCEEDED` against the live Spanner endpoint. This PR doesn't touch Spanner.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "mxtymoshyk (via GitHub)" <gi...@apache.org>.
mxtymoshyk commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-6034125325

   @kennknowles the final changes from your inline comments are in a separate PR: https://github.com/apache/beam/pull/40444. It makes 31 of the 32 files you flagged final and drops their suppressions. StatefulDoFnRunner is the one that can't be final, because ExecutableStageDoFnOperator subclasses it anonymously. I'll resolve your inline comments once that PR lands.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5966588139

   Assigning reviewers:
   
   R: @kennknowles for label java.
   R: @Abacn for label build.
   R: @Dippatel98 for label kafka.
   R: @chamikaramj for label delta.
   R: @ahmedabu98 for label iceberg.
   
   This pull request likely touches a core component ("core" label). Please review with scrutiny.
   
   
   Note: If you would like to opt out of this review, comment `assign to next reviewer`.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "mxtymoshyk (via GitHub)" <gi...@apache.org>.
mxtymoshyk commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5839644338

   After the rebase, Java PreCommit and all the SpotBugs checks are green now.
   
   The remaining red checks look like flaky tests rather than anything this PR changes:
   - The Pulsar and JMS failures are known flakes, and I've opened fixes for them: #40290 (Pulsar) and #40291 (JMS).
   - `FhirIOReadIT` timed out talking to Pub/Sub, and the Flink Container job only failed in its cleanup step because of a permissions issue.
   
   Could someone re-run the failed checks when you get a chance?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Java] Remove CT_CONSTRUCTOR_THROW from the global SpotBugs filter [beam]

Posted by "mxtymoshyk (via GitHub)" <gi...@apache.org>.
mxtymoshyk commented on PR #40008:
URL: https://github.com/apache/beam/pull/40008#issuecomment-5849703635

   Rebased onto master, which now includes the Pulsar fix (#40290). Everything is green except one BigQuery check: `FileLoadsStreamingIT` and `StorageApiDataTriggeredSchemaUpdateIT` hit `SocketTimeoutException: Read timed out` against BigQuery. The same `PreCommit Java GCP IO Direct` workflow is also failing on master's scheduled runs today, so it doesn't look related to this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org