@@ -11,12 +11,12 @@ public class StandardSession implements WxSession, InternalSession {
1111 /**
1212 * The string manager for this package.
1313 */
14- protected static final StringManager sm =
15- StringManager .getManager (Constants .Package );
14+ protected static final StringManager sm = StringManager .getManager (Constants .Package );
1615 /**
1716 * Type array.
1817 */
19- protected static final String EMPTY_ARRAY [] = new String [0 ];
18+ private static final String [] EMPTY_ARRAY = new String [0 ];
19+
2020 // ------------------------------ WxSession
2121 protected Map <String , Object > attributes = new ConcurrentHashMap <>();
2222 /**
@@ -71,20 +71,23 @@ public StandardSession(InternalSessionManager manager) {
7171 @ Override
7272 public Object getAttribute (String name ) {
7373
74- if (!isValidInternal ())
74+ if (!isValidInternal ()) {
7575 throw new IllegalStateException
76- (sm .getString ("sessionImpl.getAttribute.ise" ));
76+ (sm .getString ("sessionImpl.getAttribute.ise" ));
77+ }
7778
78- if (name == null ) return null ;
79+ if (name == null ) {
80+ return null ;
81+ }
7982
80- return ( this .attributes .get (name ) );
83+ return this .attributes .get (name );
8184 }
8285
8386 @ Override
8487 public Enumeration <String > getAttributeNames () {
85- if (!isValidInternal ())
86- throw new IllegalStateException
87- ( sm . getString ( "sessionImpl.getAttributeNames.ise" ));
88+ if (!isValidInternal ()) {
89+ throw new IllegalStateException ( sm . getString ( "sessionImpl.getAttributeNames.ise" ));
90+ }
8891
8992 Set <String > names = new HashSet <>();
9093 names .addAll (this .attributes .keySet ());
@@ -94,9 +97,9 @@ public Enumeration<String> getAttributeNames() {
9497 @ Override
9598 public void setAttribute (String name , Object value ) {
9699 // Name cannot be null
97- if (name == null )
98- throw new IllegalArgumentException
99- ( sm . getString ( "sessionImpl.setAttribute.namenull" ));
100+ if (name == null ) {
101+ throw new IllegalArgumentException ( sm . getString ( "sessionImpl.setAttribute.namenull" ));
102+ }
100103
101104 // Null value is the same as removeAttribute()
102105 if (value == null ) {
@@ -105,9 +108,9 @@ public void setAttribute(String name, Object value) {
105108 }
106109
107110 // Validate our current state
108- if (!isValidInternal ())
109- throw new IllegalStateException (sm .getString (
110- "sessionImpl.setAttribute.ise" , getIdInternal ()));
111+ if (!isValidInternal ()) {
112+ throw new IllegalStateException (sm .getString ("sessionImpl.setAttribute.ise" , getIdInternal ()));
113+ }
111114
112115 this .attributes .put (name , value );
113116
@@ -121,8 +124,7 @@ public void removeAttribute(String name) {
121124 @ Override
122125 public void invalidate () {
123126 if (!isValidInternal ())
124- throw new IllegalStateException
125- (sm .getString ("sessionImpl.invalidate.ise" ));
127+ throw new IllegalStateException (sm .getString ("sessionImpl.invalidate.ise" ));
126128
127129 // Cause this session to expire
128130 expire ();
@@ -131,12 +133,11 @@ public void invalidate() {
131133
132134 @ Override
133135 public WxSession getSession () {
134-
135136 if (this .facade == null ) {
136137 this .facade = new StandardSessionFacade (this );
137138 }
138- return (this .facade );
139139
140+ return this .facade ;
140141 }
141142
142143 /**
@@ -185,12 +186,14 @@ public void setValid(boolean isValid) {
185186
186187 @ Override
187188 public String getIdInternal () {
188- return ( this .id ) ;
189+ return this .id ;
189190 }
190191
191192 protected void removeAttributeInternal (String name ) {
192193 // Avoid NPE
193- if (name == null ) return ;
194+ if (name == null ) {
195+ return ;
196+ }
194197
195198 // Remove this attribute from our collection
196199 this .attributes .remove (name );
@@ -202,19 +205,22 @@ public void expire() {
202205 // Check to see if session has already been invalidated.
203206 // Do not check expiring at this point as expire should not return until
204207 // isValid is false
205- if (!this .isValid )
208+ if (!this .isValid ) {
206209 return ;
210+ }
207211
208212 synchronized (this ) {
209213 // Check again, now we are inside the sync so this code only runs once
210214 // Double check locking - isValid needs to be volatile
211215 // The check of expiring is to ensure that an infinite loop is not
212216 // entered as per bug 56339
213- if (this .expiring || !this .isValid )
217+ if (this .expiring || !this .isValid ) {
214218 return ;
219+ }
215220
216- if (this .manager == null )
221+ if (this .manager == null ) {
217222 return ;
223+ }
218224
219225 // Mark this session as "being expired"
220226 this .expiring = true ;
@@ -230,9 +236,9 @@ public void expire() {
230236 this .expiring = false ;
231237
232238 // Unbind any objects associated with this session
233- String keys [] = keys ();
234- for (int i = 0 ; i < keys . length ; i ++ ) {
235- removeAttributeInternal (keys [ i ] );
239+ String [] keys = keys ();
240+ for (String key : keys ) {
241+ removeAttributeInternal (key );
236242 }
237243 }
238244
@@ -273,13 +279,15 @@ public void setMaxInactiveInterval(int interval) {
273279
274280 @ Override
275281 public void setId (String id ) {
276- if ((this .id != null ) && (this .manager != null ))
282+ if ((this .id != null ) && (this .manager != null )) {
277283 this .manager .remove (this );
284+ }
278285
279286 this .id = id ;
280287
281- if (this .manager != null )
288+ if (this .manager != null ) {
282289 this .manager .add (this );
290+ }
283291 }
284292
285293 /**
@@ -295,21 +303,41 @@ protected String[] keys() {
295303
296304 @ Override
297305 public boolean equals (Object o ) {
298- if (this == o ) return true ;
299- if (!(o instanceof StandardSession )) return false ;
306+ if (this == o ) {
307+ return true ;
308+ }
309+ if (!(o instanceof StandardSession )) {
310+ return false ;
311+ }
300312
301313 StandardSession session = (StandardSession ) o ;
302314
303- if (this .creationTime != session .creationTime ) return false ;
304- if (this .expiring != session .expiring ) return false ;
305- if (this .isValid != session .isValid ) return false ;
306- if (this .maxInactiveInterval != session .maxInactiveInterval ) return false ;
307- if (this .thisAccessedTime != session .thisAccessedTime ) return false ;
308- if (!this .accessCount .equals (session .accessCount )) return false ;
309- if (!this .attributes .equals (session .attributes )) return false ;
310- if (!this .facade .equals (session .facade )) return false ;
311- if (!this .id .equals (session .id )) return false ;
312- return this .manager .equals (session .manager );
315+ if (this .creationTime != session .creationTime ) {
316+ return false ;
317+ }
318+ if (this .expiring != session .expiring ) {
319+ return false ;
320+ }
321+ if (this .isValid != session .isValid ) {
322+ return false ;
323+ }
324+ if (this .maxInactiveInterval != session .maxInactiveInterval ) {
325+ return false ;
326+ }
327+ if (this .thisAccessedTime != session .thisAccessedTime ) {
328+ return false ;
329+ }
330+ if (this .accessCount .get () != session .accessCount .get ()) {
331+ return false ;
332+ }
333+ if (!this .attributes .equals (session .attributes )) {
334+ return false ;
335+ }
336+ if (!this .facade .equals (session .facade )) {
337+ return false ;
338+ }
339+
340+ return this .id .equals (session .id ) && this .manager .equals (session .manager );
313341
314342 }
315343
0 commit comments