From 6d623927c336dc6178021748b56def10da321265 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 26 Nov 2024 15:42:56 -0800 Subject: [PATCH] Some tweaks to `@Initializer` annotations in wala.util (#1474) - Remove a couple of `@Nullable` annotations and add `@Initializer` instead, to better capture the protocol. - Remove WALA's custom `@Initializer` annotation and use the one from NullAway's annotations package, which we already depend on. --- .../java/com/ibm/wala/qual/Initializer.java | 24 ------------------- .../traverse/DFSDiscoverTimeIterator.java | 4 +++- .../graph/traverse/DFSFinishTimeIterator.java | 2 +- .../GraphDFSDiscoverTimeIterator.java | 7 +++--- 4 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 util/src/main/java/com/ibm/wala/qual/Initializer.java diff --git a/util/src/main/java/com/ibm/wala/qual/Initializer.java b/util/src/main/java/com/ibm/wala/qual/Initializer.java deleted file mode 100644 index 1cb43e3734..0000000000 --- a/util/src/main/java/com/ibm/wala/qual/Initializer.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2002 - 2022 IBM Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - */ - -package com.ibm.wala.qual; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * A method annotated with @Initializer is expected to always be invoked before the object is used. - */ -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.METHOD}) -public @interface Initializer {} diff --git a/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSDiscoverTimeIterator.java b/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSDiscoverTimeIterator.java index d17e42f65e..704aeb6d53 100644 --- a/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSDiscoverTimeIterator.java +++ b/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSDiscoverTimeIterator.java @@ -15,6 +15,7 @@ import com.ibm.wala.util.collections.NonNullSingletonIterator; import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.graph.NumberedGraph; +import com.uber.nullaway.annotations.Initializer; import java.util.ArrayList; import java.util.Iterator; import java.util.NoSuchElementException; @@ -32,9 +33,10 @@ public abstract class DFSDiscoverTimeIterator extends ArrayList implements private static final long serialVersionUID = 4238700455408861924L; /** an enumeration of all nodes to search from */ - private @Nullable Iterator roots; + private Iterator roots; /** subclass constructors must call this! */ + @Initializer protected void init(Iterator nodes) { roots = nodes; assert nodes != null; diff --git a/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSFinishTimeIterator.java b/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSFinishTimeIterator.java index 431ab8994d..e8e89730fb 100644 --- a/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSFinishTimeIterator.java +++ b/util/src/main/java/com/ibm/wala/util/graph/traverse/DFSFinishTimeIterator.java @@ -10,11 +10,11 @@ */ package com.ibm.wala.util.graph.traverse; -import com.ibm.wala.qual.Initializer; import com.ibm.wala.util.collections.EmptyIterator; import com.ibm.wala.util.collections.Iterator2Iterable; import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.graph.Graph; +import com.uber.nullaway.annotations.Initializer; import java.util.ArrayList; import java.util.Iterator; import java.util.NoSuchElementException; diff --git a/util/src/main/java/com/ibm/wala/util/graph/traverse/GraphDFSDiscoverTimeIterator.java b/util/src/main/java/com/ibm/wala/util/graph/traverse/GraphDFSDiscoverTimeIterator.java index df05cf0c17..5c094328f6 100644 --- a/util/src/main/java/com/ibm/wala/util/graph/traverse/GraphDFSDiscoverTimeIterator.java +++ b/util/src/main/java/com/ibm/wala/util/graph/traverse/GraphDFSDiscoverTimeIterator.java @@ -11,17 +11,17 @@ package com.ibm.wala.util.graph.traverse; import com.ibm.wala.util.graph.Graph; +import com.uber.nullaway.annotations.Initializer; import java.util.Iterator; -import org.jspecify.annotations.NullUnmarked; -import org.jspecify.annotations.Nullable; abstract class GraphDFSDiscoverTimeIterator extends DFSDiscoverTimeIterator { private static final long serialVersionUID = -5673397879499010863L; /** the graph being searched */ - private @Nullable Graph G; + private Graph G; + @Initializer protected void init(Graph G, Iterator nodes) { if (G == null) { throw new IllegalArgumentException("G is null"); @@ -30,7 +30,6 @@ protected void init(Graph G, Iterator nodes) { super.init(nodes); } - @NullUnmarked @Override protected Iterator getConnected(T n) { return G.getSuccNodes(n);