Skip to content
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ dependencies {
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
errorprone 'com.google.errorprone:error_prone_core:2.10.0'

implementation 'org.jspecify:jspecify:1.0.1'

testCompile 'junit:junit:4.12'
testCompile 'com.google.gwt:gwt-dev:2.9.0'
testCompile 'com.google.gwt:gwt-user:2.9.0'
Expand Down
8 changes: 6 additions & 2 deletions java/com/google/re2j/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.google.re2j.MatcherInput.Encoding;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A stateful iterator that interprets a regex {@code Pattern} on a specific input. Its interface
Expand Down Expand Up @@ -38,6 +40,7 @@
*
* @author rsc@google.com (Russ Cox)
*/
@NullMarked
public final class Matcher {
// The pattern being matched.
private final Pattern pattern;
Expand All @@ -53,6 +56,7 @@ public final class Matcher {
// The number of instructions in the pattern.
private final int numberOfInstructions;

@SuppressWarnings("nullness:initialization.field.uninitialized")
private MatcherInput matcherInput;

// The input length in UTF16 codes.
Expand Down Expand Up @@ -242,7 +246,7 @@ public String group() {
* @throws IllegalStateException if there is no match
* @throws IndexOutOfBoundsException if {@code group < 0} or {@code group > groupCount()}
*/
public String group(int group) {
public @Nullable String group(int group) {
int start = start(group);
int end = end(group);
if (start < 0 && end < 0) {
Expand All @@ -258,7 +262,7 @@ public String group(int group) {
* @param group the group name
* @throws IllegalArgumentException if no group with that name exists
*/
public String group(String group) {
public @Nullable String group(String group) {
Integer g = namedGroups.get(group);
if (g == null) {
throw new IllegalArgumentException("group '" + group + "' not found");
Expand Down
5 changes: 4 additions & 1 deletion java/com/google/re2j/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A compiled representation of an RE2 regular expression, mimicking the
Expand All @@ -27,6 +29,7 @@
*
* @author rsc@google.com (Russ Cox)
*/
@NullMarked
public final class Pattern implements Serializable {
/** Flag: case insensitive matching. */
public static final int CASE_INSENSITIVE = 1;
Expand Down Expand Up @@ -339,7 +342,7 @@ Object readResolve() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions java/com/google/re2j/PatternSyntaxException.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
*/
package com.google.re2j;

import org.jspecify.annotations.NullMarked;

/**
* An exception thrown by the parser if the pattern was invalid.
*
* Following {@code java.util.regex.PatternSyntaxException}, this is an unchecked exception.
*/
@NullMarked
public class PatternSyntaxException extends RuntimeException {

private final String error; // the nature of the error
Expand Down
Loading