• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nats.java / #2101

12 Aug 2025 11:26AM UTC coverage: 95.457% (+0.02%) from 95.433%
#2101

push

github

web-flow
Merge pull request #1387 from nats-io/info-nullability

Ensuring nullability contracts

92 of 92 new or added lines in 10 files covered. (100.0%)

108 existing lines in 12 files now uncovered.

11913 of 12480 relevant lines covered (95.46%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/main/java/io/nats/client/api/ServerInfo.java
1
// Copyright 2015-2018 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.api;
15

16
import io.nats.client.support.JsonParseException;
17
import io.nats.client.support.JsonParser;
18
import io.nats.client.support.JsonValue;
19
import io.nats.client.support.ServerVersion;
20
import org.jspecify.annotations.NonNull;
21
import org.jspecify.annotations.Nullable;
22

23
import java.util.Arrays;
24
import java.util.List;
25

26
import static io.nats.client.support.ApiConstants.*;
27
import static io.nats.client.support.JsonValueUtils.*;
28
import static io.nats.client.support.NatsConstants.UNDEFINED;
29

30
public class ServerInfo {
31

32
    public static final ServerInfo EMPTY_INFO = new ServerInfo("INFO {}");
1✔
33

34
    private final String serverId;
35
    private final String serverName;
36
    private final String version;
37
    private final String go;
38
    private final String host;
39
    private final int port;
40
    private final boolean headersSupported;
41
    private final boolean authRequired;
42
    private final boolean tlsRequired;
43
    private final boolean tlsAvailable;
44
    private final long maxPayload;
45
    private final List<String> connectURLs;
46
    private final int protocolVersion;
47
    private final byte[] nonce;
48
    private final boolean lameDuckMode;
49
    private final boolean jetStream;
50
    private final int clientId;
51
    private final String clientIp;
52
    private final String cluster;
53

54
    public ServerInfo(String json) {
1✔
55
        // INFO<sp>{ INFO<\t>{ or {
56
        if (json == null || json.length() < 6 || ('{' != json.charAt(0) && '{' != json.charAt(5))) {
1✔
57
            throw new IllegalArgumentException("Invalid Server Info");
1✔
58
        }
59

60
        JsonValue jv;
61
        try {
62
            jv = JsonParser.parse(json, json.indexOf("{"));
1✔
63
        }
UNCOV
64
        catch (JsonParseException e) {
×
UNCOV
65
            throw new IllegalArgumentException("Invalid Server Info Json");
×
66
        }
1✔
67

68
        serverId = readString(jv, SERVER_ID, UNDEFINED);
1✔
69
        serverName = readString(jv, SERVER_NAME, UNDEFINED);
1✔
70
        version = readString(jv, VERSION, "0.0.0");
1✔
71
        go = readString(jv, GO, "0.0.0");
1✔
72
        host = readString(jv, HOST, UNDEFINED);
1✔
73
        headersSupported = readBoolean(jv, HEADERS);
1✔
74
        authRequired = readBoolean(jv, AUTH_REQUIRED);
1✔
75
        nonce = readBytes(jv, NONCE);
1✔
76
        tlsRequired = readBoolean(jv, TLS_REQUIRED);
1✔
77
        tlsAvailable = readBoolean(jv, TLS_AVAILABLE);
1✔
78
        lameDuckMode = readBoolean(jv, LAME_DUCK_MODE);
1✔
79
        jetStream = readBoolean(jv, JETSTREAM);
1✔
80
        port = readInteger(jv, PORT, 0);
1✔
81
        protocolVersion = readInteger(jv, PROTO, 0);
1✔
82
        maxPayload = readLong(jv, MAX_PAYLOAD, 0);
1✔
83
        clientId = readInteger(jv, CLIENT_ID, 0);
1✔
84
        clientIp = readString(jv, CLIENT_IP, "0.0.0.0");
1✔
85
        cluster = readString(jv, CLUSTER);
1✔
86
        connectURLs = readStringListIgnoreEmpty(jv, CONNECT_URLS);
1✔
87
    }
1✔
88

89
    public boolean isLameDuckMode() {
90
        return lameDuckMode;
1✔
91
    }
92

93
    @NonNull
94
    public String getServerId() {
95
        return this.serverId;
1✔
96
    }
97

98
    @NonNull
99
    public String getServerName() {
100
        return serverName;
1✔
101
    }
102

103
    @NonNull
104
    public String getVersion() {
105
        return this.version;
1✔
106
    }
107

108
    @NonNull
109
    public String getGoVersion() {
110
        return this.go;
1✔
111
    }
112

113
    @NonNull
114
    public String getHost() {
115
        return this.host;
1✔
116
    }
117

118
    public int getPort() {
119
        return this.port;
1✔
120
    }
121

122
    public int getProtocolVersion() {
123
        return this.protocolVersion;
1✔
124
    }
125

126
    public boolean isHeadersSupported() { return this.headersSupported; }
1✔
127

128
    public boolean isAuthRequired() {
129
        return this.authRequired;
1✔
130
    }
131

132
    public boolean isTLSRequired() {
133
        return this.tlsRequired;
1✔
134
    }
135

136
    public boolean isTLSAvailable() {
137
        return tlsAvailable;
1✔
138
    }
139

140
    public long getMaxPayload() {
141
        return this.maxPayload;
1✔
142
    }
143

144
    @NonNull
145
    public List<String> getConnectURLs() {
146
        return this.connectURLs;
1✔
147
    }
148

149
    public byte @Nullable [] getNonce() {
150
        return this.nonce;
1✔
151
    }
152

153
    public boolean isJetStreamAvailable() {
154
        return this.jetStream;
1✔
155
    }
156

157
    public int getClientId() {
158
        return clientId;
1✔
159
    }
160

161
    @NonNull
162
    public String getClientIp() {
163
        return clientIp;
1✔
164
    }
165

166
    @Nullable
167
    public String getCluster() {
168
        return cluster;
1✔
169
    }
170

171
    public boolean isNewerVersionThan(String vTarget) {
172
        return ServerVersion.isNewer(version, vTarget);
1✔
173
    }
174

175
    public boolean isSameVersion(String vTarget) {
176
        return ServerVersion.isSame(version, vTarget);
1✔
177
    }
178

179
    public boolean isOlderThanVersion(String vTarget) {
180
        return ServerVersion.isOlder(version, vTarget);
1✔
181
    }
182

183
    public boolean isSameOrOlderThanVersion(String vTarget) {
184
        return ServerVersion.isSameOrOlder(version, vTarget);
1✔
185
    }
186

187
    public boolean isSameOrNewerThanVersion(String vTarget) {
188
        return ServerVersion.isSameOrNewer(version, vTarget);
1✔
189
    }
190

191
    @Override
192
    public String toString() {
193
        return "ServerInfo{" +
1✔
194
                "serverId='" + serverId + '\'' +
195
                ", serverName='" + serverName + '\'' +
196
                ", version='" + version + '\'' +
197
                ", go='" + go + '\'' +
198
                ", host='" + host + '\'' +
199
                ", port=" + port +
200
                ", headersSupported=" + headersSupported +
201
                ", authRequired=" + authRequired +
202
                ", tlsRequired=" + tlsRequired +
203
                ", tlsAvailable=" + tlsAvailable +
204
                ", maxPayload=" + maxPayload +
205
                ", connectURLs=" + connectURLs +
206
                ", protocolVersion=" + protocolVersion +
207
                ", nonce=" + Arrays.toString(nonce) +
1✔
208
                ", lameDuckMode=" + lameDuckMode +
209
                ", jetStream=" + jetStream +
210
                ", clientId=" + clientId +
211
                ", clientIp='" + clientIp + '\'' +
212
                ", cluster='" + cluster + '\'' +
213
                '}';
214
    }
215
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc