消灭不规范代码(由sonatype检测出来的)

This commit is contained in:
Binary Wang
2016-12-15 16:13:49 +08:00
parent 84a79a9760
commit 761c570cad

View File

@@ -11,12 +11,12 @@ public class StandardSession implements WxSession, InternalSession {
/** /**
* The string manager for this package. * The string manager for this package.
*/ */
protected static final StringManager sm = protected static final StringManager sm = StringManager.getManager(Constants.Package);
StringManager.getManager(Constants.Package);
/** /**
* Type array. * Type array.
*/ */
protected static final String EMPTY_ARRAY[] = new String[0]; private static final String[] EMPTY_ARRAY = new String[0];
// ------------------------------ WxSession // ------------------------------ WxSession
protected Map<String, Object> attributes = new ConcurrentHashMap<>(); protected Map<String, Object> attributes = new ConcurrentHashMap<>();
/** /**
@@ -71,20 +71,23 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public Object getAttribute(String name) { public Object getAttribute(String name) {
if (!isValidInternal()) if (!isValidInternal()) {
throw new IllegalStateException throw new IllegalStateException
(sm.getString("sessionImpl.getAttribute.ise")); (sm.getString("sessionImpl.getAttribute.ise"));
}
if (name == null) return null; if (name == null) {
return null;
}
return (this.attributes.get(name)); return this.attributes.get(name);
} }
@Override @Override
public Enumeration<String> getAttributeNames() { public Enumeration<String> getAttributeNames() {
if (!isValidInternal()) if (!isValidInternal()) {
throw new IllegalStateException throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise"));
(sm.getString("sessionImpl.getAttributeNames.ise")); }
Set<String> names = new HashSet<>(); Set<String> names = new HashSet<>();
names.addAll(this.attributes.keySet()); names.addAll(this.attributes.keySet());
@@ -94,9 +97,9 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {
// Name cannot be null // Name cannot be null
if (name == null) if (name == null) {
throw new IllegalArgumentException throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull"));
(sm.getString("sessionImpl.setAttribute.namenull")); }
// Null value is the same as removeAttribute() // Null value is the same as removeAttribute()
if (value == null) { if (value == null) {
@@ -105,9 +108,9 @@ public class StandardSession implements WxSession, InternalSession {
} }
// Validate our current state // Validate our current state
if (!isValidInternal()) if (!isValidInternal()) {
throw new IllegalStateException(sm.getString( throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal()));
"sessionImpl.setAttribute.ise", getIdInternal())); }
this.attributes.put(name, value); this.attributes.put(name, value);
@@ -121,8 +124,7 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public void invalidate() { public void invalidate() {
if (!isValidInternal()) if (!isValidInternal())
throw new IllegalStateException throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise"));
(sm.getString("sessionImpl.invalidate.ise"));
// Cause this session to expire // Cause this session to expire
expire(); expire();
@@ -131,12 +133,11 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public WxSession getSession() { public WxSession getSession() {
if (this.facade == null) { if (this.facade == null) {
this.facade = new StandardSessionFacade(this); this.facade = new StandardSessionFacade(this);
} }
return (this.facade);
return this.facade;
} }
/** /**
@@ -185,12 +186,14 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public String getIdInternal() { public String getIdInternal() {
return (this.id); return this.id;
} }
protected void removeAttributeInternal(String name) { protected void removeAttributeInternal(String name) {
// Avoid NPE // Avoid NPE
if (name == null) return; if (name == null) {
return;
}
// Remove this attribute from our collection // Remove this attribute from our collection
this.attributes.remove(name); this.attributes.remove(name);
@@ -202,19 +205,22 @@ public class StandardSession implements WxSession, InternalSession {
// Check to see if session has already been invalidated. // Check to see if session has already been invalidated.
// Do not check expiring at this point as expire should not return until // Do not check expiring at this point as expire should not return until
// isValid is false // isValid is false
if (!this.isValid) if (!this.isValid) {
return; return;
}
synchronized (this) { synchronized (this) {
// Check again, now we are inside the sync so this code only runs once // Check again, now we are inside the sync so this code only runs once
// Double check locking - isValid needs to be volatile // Double check locking - isValid needs to be volatile
// The check of expiring is to ensure that an infinite loop is not // The check of expiring is to ensure that an infinite loop is not
// entered as per bug 56339 // entered as per bug 56339
if (this.expiring || !this.isValid) if (this.expiring || !this.isValid) {
return; return;
}
if (this.manager == null) if (this.manager == null) {
return; return;
}
// Mark this session as "being expired" // Mark this session as "being expired"
this.expiring = true; this.expiring = true;
@@ -230,9 +236,9 @@ public class StandardSession implements WxSession, InternalSession {
this.expiring = false; this.expiring = false;
// Unbind any objects associated with this session // Unbind any objects associated with this session
String keys[] = keys(); String[] keys = keys();
for (int i = 0; i < keys.length; i++) { for (String key : keys) {
removeAttributeInternal(keys[i]); removeAttributeInternal(key);
} }
} }
@@ -273,13 +279,15 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public void setId(String id) { public void setId(String id) {
if ((this.id != null) && (this.manager != null)) if ((this.id != null) && (this.manager != null)) {
this.manager.remove(this); this.manager.remove(this);
}
this.id = id; this.id = id;
if (this.manager != null) if (this.manager != null) {
this.manager.add(this); this.manager.add(this);
}
} }
/** /**
@@ -295,21 +303,41 @@ public class StandardSession implements WxSession, InternalSession {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (!(o instanceof StandardSession)) return false; return true;
}
if (!(o instanceof StandardSession)) {
return false;
}
StandardSession session = (StandardSession) o; StandardSession session = (StandardSession) o;
if (this.creationTime != session.creationTime) return false; if (this.creationTime != session.creationTime) {
if (this.expiring != session.expiring) return false; return false;
if (this.isValid != session.isValid) return false; }
if (this.maxInactiveInterval != session.maxInactiveInterval) return false; if (this.expiring != session.expiring) {
if (this.thisAccessedTime != session.thisAccessedTime) return false; return false;
if (this.accessCount.get() != session.accessCount.get()) return false; }
if (!this.attributes.equals(session.attributes)) return false; if (this.isValid != session.isValid) {
if (!this.facade.equals(session.facade)) return false; return false;
if (!this.id.equals(session.id)) return false; }
return this.manager.equals(session.manager); if (this.maxInactiveInterval != session.maxInactiveInterval) {
return false;
}
if (this.thisAccessedTime != session.thisAccessedTime) {
return false;
}
if (this.accessCount.get() != session.accessCount.get()) {
return false;
}
if (!this.attributes.equals(session.attributes)) {
return false;
}
if (!this.facade.equals(session.facade)) {
return false;
}
return this.id.equals(session.id) && this.manager.equals(session.manager);
} }