29
29
import rocks .xmpp .util .cache .LruCache ;
30
30
31
31
import java .net .IDN ;
32
- import java .nio .charset .StandardCharsets ;
32
+ import java .nio .charset .Charset ;
33
33
import java .text .Normalizer ;
34
34
import java .util .Map ;
35
- import java .util .Objects ;
36
35
import java .util .regex .Matcher ;
37
36
import java .util .regex .Pattern ;
38
37
@@ -109,6 +108,10 @@ private FullJid(final CharSequence local, final CharSequence domain, final CharS
109
108
110
109
final String unescapedLocalPart ;
111
110
111
+ if (domain == null ) {
112
+ throw new NullPointerException ();
113
+ }
114
+
112
115
if (doUnescape ) {
113
116
unescapedLocalPart = unescape (local );
114
117
} else {
@@ -126,7 +129,7 @@ private FullJid(final CharSequence local, final CharSequence domain, final CharS
126
129
// character MUST be stripped before any other canonicalization steps
127
130
// are taken.
128
131
// Also validate, that the domain name can be converted to ASCII, i.e. validate the domain name (e.g. must not start with "_").
129
- final String strDomain = IDN .toASCII (LABEL_SEPARATOR_FINAL .matcher (Objects . requireNonNull ( domain ) ).replaceAll ("" ), IDN .USE_STD3_ASCII_RULES );
132
+ final String strDomain = IDN .toASCII (LABEL_SEPARATOR_FINAL .matcher (domain ).replaceAll ("" ), IDN .USE_STD3_ASCII_RULES );
130
133
enforcedLocalPart = escapedLocalPart != null ? PrecisProfiles .USERNAME_CASE_MAPPED .enforce (escapedLocalPart ) : null ;
131
134
enforcedResource = resource != null ? PrecisProfiles .OPAQUE_STRING .enforce (resource ) : null ;
132
135
// See https://tools.ietf.org/html/rfc5895#section-2
@@ -152,23 +155,26 @@ public Jid asBareJid() {
152
155
153
156
@ Override
154
157
public Jid withLocal (CharSequence local ) {
155
- if (Objects . equals ( local , this .getLocal ())) {
158
+ if (local == this . getLocal () || local != null && local . equals ( this .getLocal ())) {
156
159
return this ;
157
160
}
158
161
return new FullJid (local , getDomain (), getResource (), false , null );
159
162
}
160
163
161
164
@ Override
162
165
public Jid withResource (CharSequence resource ) {
163
- if (Objects . equals ( resource , this .getResource ())) {
166
+ if (resource == this . getResource () || resource != null && resource . equals ( this .getResource ())) {
164
167
return this ;
165
168
}
166
169
return new FullJid (getLocal (), getDomain (), resource , false , asBareJid ());
167
170
}
168
171
169
172
@ Override
170
173
public Jid atSubdomain (CharSequence subdomain ) {
171
- return new FullJid (getLocal (), Objects .requireNonNull (subdomain ) + "." + getDomain (), getResource (), false , null );
174
+ if (subdomain == null ) {
175
+ throw new NullPointerException ();
176
+ }
177
+ return new FullJid (getLocal (), subdomain + "." + getDomain (), getResource (), false , null );
172
178
}
173
179
174
180
@ Override
@@ -206,7 +212,9 @@ public String getResource() {
206
212
* @see <a href="https://xmpp.org/extensions/xep-0106.html">XEP-0106: JID Escaping</a>
207
213
*/
208
214
static Jid of (String jid , final boolean doUnescape ) {
209
- Objects .requireNonNull (jid , "jid must not be null." );
215
+ if (jid == null ) {
216
+ throw new NullPointerException ("jid must not be null." );
217
+ }
210
218
211
219
jid = jid .trim ();
212
220
@@ -278,7 +286,9 @@ private static String unescape(final CharSequence localPart) {
278
286
}
279
287
280
288
private static void validateDomain (String domain ) {
281
- Objects .requireNonNull (domain , "domain must not be null." );
289
+ if (domain == null ) {
290
+ throw new NullPointerException ("domain must not be null." );
291
+ }
282
292
if (domain .contains ("@" )) {
283
293
// Prevent misuse of API.
284
294
throw new IllegalArgumentException ("domain must not contain a '@' sign" );
@@ -297,7 +307,7 @@ private static void validateLength(CharSequence value, CharSequence part) {
297
307
if (value .length () == 0 ) {
298
308
throw new IllegalArgumentException (part + " must not be empty." );
299
309
}
300
- if (value .toString ().getBytes (StandardCharsets . UTF_8 ).length > 1023 ) {
310
+ if (value .toString ().getBytes (Charset . forName ( "UTF-8" ) ).length > 1023 ) {
301
311
throw new IllegalArgumentException (part + " must not be greater than 1023 bytes." );
302
312
}
303
313
}
@@ -391,7 +401,7 @@ public final String getResource() {
391
401
*/
392
402
@ Override
393
403
public final Jid withLocal (CharSequence local ) {
394
- if (Objects . equals ( local , this .getLocal ())) {
404
+ if (local == this . getLocal () || local != null && local . equals ( this .getLocal ())) {
395
405
return this ;
396
406
}
397
407
return new FullJid (local , getDomain (), getResource (), false , null );
@@ -408,7 +418,7 @@ public final Jid withLocal(CharSequence local) {
408
418
*/
409
419
@ Override
410
420
public final Jid withResource (CharSequence resource ) {
411
- if (Objects . equals ( resource , this .getResource ())) {
421
+ if (resource == this . getResource () || resource != null && resource . equals ( this .getResource ())) {
412
422
return this ;
413
423
}
414
424
return new FullJid (getLocal (), getDomain (), resource , false , asBareJid ());
@@ -424,7 +434,10 @@ public final Jid withResource(CharSequence resource) {
424
434
*/
425
435
@ Override
426
436
public final Jid atSubdomain (CharSequence subdomain ) {
427
- return new FullJid (getLocal (), Objects .requireNonNull (subdomain ) + "." + getDomain (), getResource (), false , null );
437
+ if (subdomain != null ) {
438
+ throw new NullPointerException ();
439
+ }
440
+ return new FullJid (getLocal (), subdomain + "." + getDomain (), getResource (), false , null );
428
441
}
429
442
430
443
/**
0 commit comments