@@ -11,12 +11,12 @@ public class StandardSession implements WxSession, InternalSession {
11
11
/**
12
12
* The string manager for this package.
13
13
*/
14
- protected static final StringManager sm =
15
- StringManager .getManager (Constants .Package );
14
+ protected static final StringManager sm = StringManager .getManager (Constants .Package );
16
15
/**
17
16
* Type array.
18
17
*/
19
- protected static final String EMPTY_ARRAY [] = new String [0 ];
18
+ private static final String [] EMPTY_ARRAY = new String [0 ];
19
+
20
20
// ------------------------------ WxSession
21
21
protected Map <String , Object > attributes = new ConcurrentHashMap <>();
22
22
/**
@@ -71,20 +71,23 @@ public StandardSession(InternalSessionManager manager) {
71
71
@ Override
72
72
public Object getAttribute (String name ) {
73
73
74
- if (!isValidInternal ())
74
+ if (!isValidInternal ()) {
75
75
throw new IllegalStateException
76
- (sm .getString ("sessionImpl.getAttribute.ise" ));
76
+ (sm .getString ("sessionImpl.getAttribute.ise" ));
77
+ }
77
78
78
- if (name == null ) return null ;
79
+ if (name == null ) {
80
+ return null ;
81
+ }
79
82
80
- return ( this .attributes .get (name ) );
83
+ return this .attributes .get (name );
81
84
}
82
85
83
86
@ Override
84
87
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
+ }
88
91
89
92
Set <String > names = new HashSet <>();
90
93
names .addAll (this .attributes .keySet ());
@@ -94,9 +97,9 @@ public Enumeration<String> getAttributeNames() {
94
97
@ Override
95
98
public void setAttribute (String name , Object value ) {
96
99
// 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
+ }
100
103
101
104
// Null value is the same as removeAttribute()
102
105
if (value == null ) {
@@ -105,9 +108,9 @@ public void setAttribute(String name, Object value) {
105
108
}
106
109
107
110
// 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
+ }
111
114
112
115
this .attributes .put (name , value );
113
116
@@ -121,8 +124,7 @@ public void removeAttribute(String name) {
121
124
@ Override
122
125
public void invalidate () {
123
126
if (!isValidInternal ())
124
- throw new IllegalStateException
125
- (sm .getString ("sessionImpl.invalidate.ise" ));
127
+ throw new IllegalStateException (sm .getString ("sessionImpl.invalidate.ise" ));
126
128
127
129
// Cause this session to expire
128
130
expire ();
@@ -131,12 +133,11 @@ public void invalidate() {
131
133
132
134
@ Override
133
135
public WxSession getSession () {
134
-
135
136
if (this .facade == null ) {
136
137
this .facade = new StandardSessionFacade (this );
137
138
}
138
- return (this .facade );
139
139
140
+ return this .facade ;
140
141
}
141
142
142
143
/**
@@ -185,12 +186,14 @@ public void setValid(boolean isValid) {
185
186
186
187
@ Override
187
188
public String getIdInternal () {
188
- return ( this .id ) ;
189
+ return this .id ;
189
190
}
190
191
191
192
protected void removeAttributeInternal (String name ) {
192
193
// Avoid NPE
193
- if (name == null ) return ;
194
+ if (name == null ) {
195
+ return ;
196
+ }
194
197
195
198
// Remove this attribute from our collection
196
199
this .attributes .remove (name );
@@ -202,19 +205,22 @@ public void expire() {
202
205
// Check to see if session has already been invalidated.
203
206
// Do not check expiring at this point as expire should not return until
204
207
// isValid is false
205
- if (!this .isValid )
208
+ if (!this .isValid ) {
206
209
return ;
210
+ }
207
211
208
212
synchronized (this ) {
209
213
// Check again, now we are inside the sync so this code only runs once
210
214
// Double check locking - isValid needs to be volatile
211
215
// The check of expiring is to ensure that an infinite loop is not
212
216
// entered as per bug 56339
213
- if (this .expiring || !this .isValid )
217
+ if (this .expiring || !this .isValid ) {
214
218
return ;
219
+ }
215
220
216
- if (this .manager == null )
221
+ if (this .manager == null ) {
217
222
return ;
223
+ }
218
224
219
225
// Mark this session as "being expired"
220
226
this .expiring = true ;
@@ -230,9 +236,9 @@ public void expire() {
230
236
this .expiring = false ;
231
237
232
238
// 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 );
236
242
}
237
243
}
238
244
@@ -273,13 +279,15 @@ public void setMaxInactiveInterval(int interval) {
273
279
274
280
@ Override
275
281
public void setId (String id ) {
276
- if ((this .id != null ) && (this .manager != null ))
282
+ if ((this .id != null ) && (this .manager != null )) {
277
283
this .manager .remove (this );
284
+ }
278
285
279
286
this .id = id ;
280
287
281
- if (this .manager != null )
288
+ if (this .manager != null ) {
282
289
this .manager .add (this );
290
+ }
283
291
}
284
292
285
293
/**
@@ -295,21 +303,41 @@ protected String[] keys() {
295
303
296
304
@ Override
297
305
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
+ }
300
312
301
313
StandardSession session = (StandardSession ) o ;
302
314
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 );
313
341
314
342
}
315
343
0 commit comments