Skip to content

Commit

Permalink
Annotate StackWalker. (#68)
Browse files Browse the repository at this point in the history
This builds on
typetools/jdk@fd7576e.
I think that PR was actually unnecessary for Checker-Framework purposes
because type-parameter upper bounds default to `@Nullable` there, but we
do need such a change on the JSpecify side. This PR also adds a
`@Nullable` annotation to `StackFrame.getFileName()`.

Co-authored-by: Adam Gent <[email protected]>
  • Loading branch information
cpovirk and agentgt authored Oct 7, 2024
1 parent 8f47457 commit 694ca99
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/java.base/share/classes/java/lang/StackWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
package java.lang;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import jdk.internal.reflect.CallerSensitive;

import java.lang.invoke.MethodType;
Expand Down Expand Up @@ -89,6 +92,7 @@
*
* @since 9
*/
@NullMarked
public final class StackWalker {
/**
* A {@code StackFrame} object represents a method invocation returned by
Expand Down Expand Up @@ -213,7 +217,7 @@ public default String getDescriptor() {
*
* @jvms 4.7.10 The {@code SourceFile} Attribute
*/
public String getFileName();
public @Nullable String getFileName();

/**
* Returns the line number of the source line containing the execution
Expand Down Expand Up @@ -528,7 +532,7 @@ private static EnumSet<Option> toEnumSet(Set<Option> options) {
* {@linkplain StackFrame stack frame}.
*/
@CallerSensitive
public <T> T walk(Function<? super Stream<StackFrame>, ? extends T> function) {
public <T extends @Nullable Object> T walk(Function<? super Stream<StackFrame>, ? extends T> function) {
// Returning a Stream<StackFrame> would be unsafe, as the stream could
// be used to access the stack frames in an uncontrolled manner. For
// example, a caller might pass a Spliterator of stack frames after one
Expand Down

0 comments on commit 694ca99

Please sign in to comment.