2929import  rocks .xmpp .util .cache .LruCache ;
3030
3131import  java .net .IDN ;
32- import  java .nio .charset .StandardCharsets ;
32+ import  java .nio .charset .Charset ;
3333import  java .text .Normalizer ;
3434import  java .util .Map ;
35- import  java .util .Objects ;
3635import  java .util .regex .Matcher ;
3736import  java .util .regex .Pattern ;
3837
@@ -109,6 +108,10 @@ private FullJid(final CharSequence local, final CharSequence domain, final CharS
109108
110109        final  String  unescapedLocalPart ;
111110
111+         if  (domain  == null ) {
112+             throw  new  NullPointerException ();
113+         }
114+ 
112115        if  (doUnescape ) {
113116            unescapedLocalPart  = unescape (local );
114117        } else  {
@@ -126,7 +129,7 @@ private FullJid(final CharSequence local, final CharSequence domain, final CharS
126129        // character MUST be stripped before any other canonicalization steps 
127130        // are taken. 
128131        // 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 );
130133        enforcedLocalPart  = escapedLocalPart  != null  ? PrecisProfiles .USERNAME_CASE_MAPPED .enforce (escapedLocalPart ) : null ;
131134        enforcedResource  = resource  != null  ? PrecisProfiles .OPAQUE_STRING .enforce (resource ) : null ;
132135        // See https://tools.ietf.org/html/rfc5895#section-2 
@@ -152,23 +155,26 @@ public Jid asBareJid() {
152155
153156                @ Override 
154157                public  Jid  withLocal (CharSequence  local ) {
155-                     if  (Objects . equals ( local ,  this .getLocal ())) {
158+                     if  (local  ==  this . getLocal () ||  local  !=  null  &&  local . equals ( this .getLocal ())) {
156159                        return  this ;
157160                    }
158161                    return  new  FullJid (local , getDomain (), getResource (), false , null );
159162                }
160163
161164                @ Override 
162165                public  Jid  withResource (CharSequence  resource ) {
163-                     if  (Objects . equals ( resource ,  this .getResource ())) {
166+                     if  (resource  ==  this . getResource () ||  resource  !=  null  &&  resource . equals ( this .getResource ())) {
164167                        return  this ;
165168                    }
166169                    return  new  FullJid (getLocal (), getDomain (), resource , false , asBareJid ());
167170                }
168171
169172                @ Override 
170173                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 );
172178                }
173179
174180                @ Override 
@@ -206,7 +212,9 @@ public String getResource() {
206212     * @see <a href="https://xmpp.org/extensions/xep-0106.html">XEP-0106: JID Escaping</a> 
207213     */ 
208214    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+         }
210218
211219        jid  = jid .trim ();
212220
@@ -278,7 +286,9 @@ private static String unescape(final CharSequence localPart) {
278286    }
279287
280288    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+         }
282292        if  (domain .contains ("@" )) {
283293            // Prevent misuse of API. 
284294            throw  new  IllegalArgumentException ("domain must not contain a '@' sign" );
@@ -297,7 +307,7 @@ private static void validateLength(CharSequence value, CharSequence part) {
297307            if  (value .length () == 0 ) {
298308                throw  new  IllegalArgumentException (part  + " must not be empty." );
299309            }
300-             if  (value .toString ().getBytes (StandardCharsets . UTF_8 ).length  > 1023 ) {
310+             if  (value .toString ().getBytes (Charset . forName ( "UTF-8" ) ).length  > 1023 ) {
301311                throw  new  IllegalArgumentException (part  + " must not be greater than 1023 bytes." );
302312            }
303313        }
@@ -391,7 +401,7 @@ public final String getResource() {
391401     */ 
392402    @ Override 
393403    public  final  Jid  withLocal (CharSequence  local ) {
394-         if  (Objects . equals ( local ,  this .getLocal ())) {
404+         if  (local  ==  this . getLocal () ||  local  !=  null  &&  local . equals ( this .getLocal ())) {
395405            return  this ;
396406        }
397407        return  new  FullJid (local , getDomain (), getResource (), false , null );
@@ -408,7 +418,7 @@ public final Jid withLocal(CharSequence local) {
408418     */ 
409419    @ Override 
410420    public  final  Jid  withResource (CharSequence  resource ) {
411-         if  (Objects . equals ( resource ,  this .getResource ())) {
421+         if  (resource  ==  this . getResource () ||  resource  !=  null  &&  resource . equals ( this .getResource ())) {
412422            return  this ;
413423        }
414424        return  new  FullJid (getLocal (), getDomain (), resource , false , asBareJid ());
@@ -424,7 +434,10 @@ public final Jid withResource(CharSequence resource) {
424434     */ 
425435    @ Override 
426436    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 );
428441    }
429442
430443    /** 
0 commit comments