Skip to content

Commit 5fdc912

Browse files
authored
Merge branch 'main' into auth_violation_reproduce_program
2 parents cf68dbd + 5fb9f42 commit 5fdc912

File tree

88 files changed

+731
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+731
-185
lines changed

build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ plugins {
1515

1616
def jarVersion = "2.21.3"
1717

18-
def isRelease = System.getenv("BUILD_EVENT") == "release"
18+
def buildEvent = System.getenv("BUILD_EVENT")
19+
def isLocal = buildEvent == null
20+
def isRelease = buildEvent == "release"
1921
def brn = System.getenv("BRANCH_REF_NAME")
2022
def snap = brn == null || brn.equals("") ? "-SNAPSHOT" : "." + brn + "-SNAPSHOT"
2123

@@ -37,6 +39,7 @@ repositories {
3739

3840
dependencies {
3941
implementation 'org.bouncycastle:bcprov-lts8on:2.73.7'
42+
implementation 'org.jetbrains:annotations:26.0.2'
4043

4144
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
4245
testImplementation 'io.nats:jnats-server-runner:2.0.0'
@@ -81,10 +84,15 @@ test {
8184
events "started", "passed", "skipped", "failed"
8285
showStandardStreams = true
8386
}
84-
retry {
85-
failOnPassedAfterRetry = false
86-
maxFailures = 5
87-
maxRetries = 5
87+
if (isLocal) {
88+
failFast = true
89+
}
90+
else {
91+
retry {
92+
failOnPassedAfterRetry = false
93+
maxFailures = 5
94+
maxRetries = 5
95+
}
8896
}
8997
maxParallelForks = Runtime.runtime.availableProcessors()
9098
}

src/examples/java/io/nats/examples/service/ServiceExample.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.nats.client.support.JsonValue;
1919
import io.nats.client.support.JsonValueUtils;
2020
import io.nats.service.*;
21+
import org.jetbrains.annotations.NotNull;
2122

2223
import java.io.IOException;
2324
import java.util.Arrays;
@@ -233,11 +234,13 @@ public ExampleStatsData(String sData, int iData) {
233234
}
234235

235236
@Override
237+
@NotNull
236238
public String toJson() {
237239
return toJsonValue().toJson();
238240
}
239241

240242
@Override
243+
@NotNull
241244
public JsonValue toJsonValue() {
242245
Map<String, JsonValue> map = new HashMap<>();
243246
map.put("sdata", new JsonValue(sData));

src/main/java/io/nats/client/BaseConsumeOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.nats.client.support.JsonParser;
1818
import io.nats.client.support.JsonSerializable;
1919
import io.nats.client.support.JsonValue;
20+
import org.jetbrains.annotations.NotNull;
2021

2122
import static io.nats.client.support.ApiConstants.*;
2223
import static io.nats.client.support.JsonUtils.*;
@@ -72,6 +73,7 @@ protected BaseConsumeOptions(Builder<?, ?> b) {
7273
}
7374

7475
@Override
76+
@NotNull
7577
public String toJson() {
7678
StringBuilder sb = beginJson();
7779
addField(sb, MESSAGES, messages);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 The NATS Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at:
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package io.nats.client;
15+
16+
public class NatsSystemClock {
17+
private static NatsSystemClockProvider PROVIDER = new NatsSystemClockProvider() {};
18+
19+
public static void setProvider(final NatsSystemClockProvider provider) {
20+
PROVIDER = provider == null ? new NatsSystemClockProvider() {} : provider;
21+
}
22+
23+
public static long currentTimeMillis() {
24+
return PROVIDER.currentTimeMillis();
25+
}
26+
27+
public static long nanoTime() {
28+
return PROVIDER.nanoTime();
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2025 The NATS Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at:
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package io.nats.client;
15+
16+
public interface NatsSystemClockProvider {
17+
default long currentTimeMillis() { return System.currentTimeMillis(); }
18+
default long nanoTime() { return System.nanoTime(); }
19+
}

src/main/java/io/nats/client/PullRequestOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import io.nats.client.support.JsonSerializable;
1717
import io.nats.client.support.JsonUtils;
18+
import org.jetbrains.annotations.NotNull;
1819

1920
import java.time.Duration;
2021

@@ -47,6 +48,7 @@ public PullRequestOptions(Builder b) {
4748
}
4849

4950
@Override
51+
@NotNull
5052
public String toJson() {
5153
StringBuilder sb = JsonUtils.beginJson();
5254
JsonUtils.addField(sb, BATCH, batchSize);

src/main/java/io/nats/client/PurgeOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import io.nats.client.support.JsonSerializable;
1717
import io.nats.client.support.JsonUtils;
18+
import org.jetbrains.annotations.NotNull;
1819

1920
import static io.nats.client.support.ApiConstants.*;
2021
import static io.nats.client.support.JsonUtils.beginJson;
@@ -37,6 +38,7 @@ private PurgeOptions(String subject, long seq, long keep) {
3738
}
3839

3940
@Override
41+
@NotNull
4042
public String toJson() {
4143
StringBuilder sb = beginJson();
4244
JsonUtils.addField(sb, FILTER, subject);

src/main/java/io/nats/client/api/AccountLimits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class AccountLimits {
2626

2727
private final long maxMemory;
2828
private final long maxStorage;
29-
private final long maxStreams;
30-
private final long maxConsumers;
31-
private final long maxAckPending;
29+
private final long maxStreams; // should be an int
30+
private final long maxConsumers; // should be an int
31+
private final long maxAckPending; // should be an int
3232
private final long memoryMaxStreamBytes;
3333
private final long storageMaxStreamBytes;
3434
private final boolean maxBytesRequired;

src/main/java/io/nats/client/api/AccountStatistics.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import io.nats.client.Message;
1717
import io.nats.client.support.JsonValue;
18+
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.annotations.Nullable;
1820

1921
import java.util.HashMap;
2022
import java.util.Map;
@@ -26,8 +28,7 @@
2628
/**
2729
* The JetStream Account Statistics
2830
*/
29-
public class AccountStatistics
30-
extends ApiResponse<AccountStatistics> {
31+
public class AccountStatistics extends ApiResponse<AccountStatistics> {
3132

3233
private final AccountTier rollupTier;
3334
private final String domain;
@@ -111,9 +112,10 @@ public AccountLimits getLimits() {
111112
}
112113

113114
/**
114-
* Gets the account domain
115+
* Gets the account domain. May be null
115116
* @return the domain
116117
*/
118+
@Nullable
117119
public String getDomain() {
118120
return domain;
119121
}
@@ -122,14 +124,16 @@ public String getDomain() {
122124
* Gets the account api stats
123125
* @return the ApiStats object
124126
*/
127+
@NotNull
125128
public ApiStats getApi() {
126129
return api;
127130
}
128131

129132
/**
130-
* Gets the map of the Account Tiers by tier name
133+
* Gets the map of the Account Tiers by tier name. May be empty, but never null.
131134
* @return the map
132135
*/
136+
@NotNull
133137
public Map<String, AccountTier> getTiers() {
134138
return tiers;
135139
}

src/main/java/io/nats/client/api/AccountTier.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.nats.client.api;
1515

1616
import io.nats.client.support.JsonValue;
17+
import org.jetbrains.annotations.NotNull;
1718

1819
import static io.nats.client.support.ApiConstants.*;
1920
import static io.nats.client.support.JsonValueUtils.readInteger;
@@ -110,6 +111,7 @@ public int getConsumers() {
110111
* The limits of this tier.
111112
* @return the limits object
112113
*/
114+
@NotNull
113115
public AccountLimits getLimits() {
114116
return limits;
115117
}

src/main/java/io/nats/client/api/AckPolicy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.nats.client.api;
1515

16+
import org.jetbrains.annotations.Nullable;
17+
1618
import java.util.HashMap;
1719
import java.util.Map;
1820

@@ -52,6 +54,7 @@ public String toString() {
5254
}
5355
}
5456

57+
@Nullable
5558
public static AckPolicy get(String value) {
5659
return strEnumHash.get(value);
5760
}

src/main/java/io/nats/client/api/ApiResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.nats.client.JetStreamApiException;
1717
import io.nats.client.Message;
1818
import io.nats.client.support.*;
19+
import org.jetbrains.annotations.Nullable;
1920

2021
import static io.nats.client.support.ApiConstants.ERROR;
2122
import static io.nats.client.support.ApiConstants.TYPE;
@@ -90,6 +91,7 @@ public T throwOnHasError() throws JetStreamApiException {
9091
return (T)this;
9192
}
9293

94+
@Nullable
9395
public JsonValue getJv() {
9496
return jv;
9597
}
@@ -98,6 +100,7 @@ public boolean hasError() {
98100
return error != null;
99101
}
100102

103+
@Nullable
101104
public String getType() {
102105
return type;
103106
}
@@ -110,14 +113,17 @@ public int getApiErrorCode() {
110113
return error == null ? Error.NOT_SET : error.getApiErrorCode();
111114
}
112115

116+
@Nullable
113117
public String getDescription() {
114118
return error == null ? null : error.getDescription();
115119
}
116120

121+
@Nullable
117122
public String getError() {
118123
return error == null ? null : error.toString();
119124
}
120125

126+
@Nullable
121127
public Error getErrorObject() {
122128
return error;
123129
}

src/main/java/io/nats/client/api/ClusterInfo.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.nats.client.api;
1515

1616
import io.nats.client.support.JsonValue;
17+
import org.jetbrains.annotations.Nullable;
1718

1819
import java.util.List;
1920

@@ -39,14 +40,29 @@ static ClusterInfo optionalInstance(JsonValue v) {
3940
replicas = Replica.optionalListOf(readValue(v, REPLICAS));
4041
}
4142

43+
/**
44+
* The cluster name. Technically can be null
45+
* @return the cluster or null
46+
*/
47+
@Nullable
4248
public String getName() {
4349
return name;
4450
}
4551

52+
/**
53+
* The server name of the RAFT leader
54+
* @return the leader or null
55+
*/
56+
@Nullable
4657
public String getLeader() {
4758
return leader;
4859
}
4960

61+
/**
62+
* The members of the RAFT cluster. May be null if there are no replicas.
63+
* @return the replicas or null
64+
*/
65+
@Nullable
5066
public List<Replica> getReplicas() {
5167
return replicas;
5268
}

src/main/java/io/nats/client/api/CompressionOption.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.nats.client.api;
1515

16+
import org.jetbrains.annotations.Nullable;
17+
1618
import java.util.HashMap;
1719
import java.util.Map;
1820

@@ -42,6 +44,7 @@ public String toString() {
4244
}
4345
}
4446

47+
@Nullable
4548
public static CompressionOption get(String value) {
4649
return strEnumHash.get(value);
4750
}

0 commit comments

Comments
 (0)