Skip to content

Commit

Permalink
Merge pull request #4478 from sgflt/issue-4281-deadlock-isValid-side-…
Browse files Browse the repository at this point in the history
…effect

CUSTCOM-260 Fixed possible deadlock in StandardSession
  • Loading branch information
David Matějček authored Apr 16, 2020
2 parents 59906e0 + f6a945b commit 9e59979
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,6 @@ public StandardSessionFacade run(){
}


/**
* Return the <code>isValid</code> flag for this session.
*/
@Override
public boolean isValid() {

Expand All @@ -716,15 +713,6 @@ public boolean isValid() {
return true;
}

/* SJSAS 6329289
if (maxInactiveInterval >= 0) {
long timeNow = System.currentTimeMillis();
int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
if (timeIdle >= maxInactiveInterval) {
expire(true);
}
}
*/
// START SJSAS 6329289
if (hasExpired()) {
expire(true);
Expand Down Expand Up @@ -1311,6 +1299,7 @@ public ServletContext getServletContext() {
* Java Servlet API.
*/
@Override
@Deprecated
public HttpSessionContext getSessionContext() {
if (sessionContext == null)
sessionContext = new StandardSessionContext();
Expand Down Expand Up @@ -1357,13 +1346,22 @@ public Map<String, Object> getAttributes() {
@Override
public Enumeration<String> getAttributeNames() {

if (!isValid())
if (!isValid()) {
throw new IllegalStateException
("getAttributeNames: " + RESOURCE_BUNDLE.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION));
("getAttributeNames: " + RESOURCE_BUNDLE.getString(LogFacade.SESSION_INVALIDATED_EXCEPTION));
}

return getAttributeNamesInternal();

return (new Enumerator<>(attributes.keySet(), true));
}

/**
* Returns names of attributes even for expired session.
*
* @return names of attributes ignoring state of session
*/
protected Enumerator<String> getAttributeNamesInternal() {
return new Enumerator<>(attributes.keySet(), true);
}


Expand All @@ -1380,6 +1378,7 @@ public Enumeration<String> getAttributeNames() {
* <code>getAttribute()</code>
*/
@Override
@Deprecated
public Object getValue(String name) {
return (getAttribute(name));
}
Expand All @@ -1396,6 +1395,7 @@ public Object getValue(String name) {
* <code>getAttributeNames()</code>
*/
@Override
@Deprecated
public String[] getValueNames() {

if (!isValid())
Expand Down Expand Up @@ -1640,6 +1640,7 @@ public boolean isNew() {
* <code>setAttribute()</code>
*/
@Override
@Deprecated
public void putValue(String name, Object value) {
setAttribute(name, value);
}
Expand Down Expand Up @@ -1787,6 +1788,7 @@ public void removeAttribute(String name, boolean notify,
* <code>removeAttribute()</code>
*/
@Override
@Deprecated
public void removeValue(String name) {
removeAttribute(name);
}
Expand Down Expand Up @@ -2457,7 +2459,7 @@ private static Cache<Object, Boolean> buildSerializableCache() {
* @deprecated As of Java Servlet API 2.1 with no replacement. The
* interface will be removed in a future version of this API.
*/

@Deprecated
final class StandardSessionContext implements HttpSessionContext {


Expand All @@ -2472,6 +2474,7 @@ final class StandardSessionContext implements HttpSessionContext {
* and will be removed in a future version of the API.
*/
@Override
@Deprecated
public Enumeration<String> getIds() {
return (new Enumerator<>(dummy));
}
Expand All @@ -2488,6 +2491,7 @@ public Enumeration<String> getIds() {
* future version of the API.
*/
@Override
@Deprecated
public HttpSession getSession(String id) {
return (null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,39 @@ private void writeObject(ObjectOutputStream stream) throws IOException {
/**
* Return a string representation of this object.
*/
public String superToString() {
private CharSequence superToString() {

StringBuilder sb = new StringBuilder(1000);
final StringBuilder sb = new StringBuilder(1000);
sb.append("BaseHASession[");
sb.append(id);
sb.append("]");

sb.append("\n");
sb.append("isValid:" + this.isValid);
sb.append("isValid:").append(getIsValid());

if (this.isValid) {
Enumeration<String> attrNamesEnum = getAttributeNames();
if (getIsValid()) {
final Enumeration<String> attrNamesEnum = getAttributeNamesInternal();
while(attrNamesEnum.hasMoreElements()) {
String nextAttrName = attrNamesEnum.nextElement();
Object nextAttrValue = getAttributeInternal(nextAttrName);
final String nextAttrName = attrNamesEnum.nextElement();
final Object nextAttrValue = getAttributeInternal(nextAttrName);
sb.append("\n");
sb.append("attrName = " + nextAttrName);
sb.append(" : attrValue = " + nextAttrValue);
sb.append("attrName = ").append(nextAttrName);
sb.append(" : attrValue = ").append(nextAttrValue);
}
}

return sb.toString();
return sb;
// END S1AS
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder(200);
//sb.append(super.toString());
sb.append(this.superToString());
sb.append(" ssoid: " + this.getSsoId());
sb.append(" userName: " + this.getUserName());
sb.append(" version: " + this.getVersion());
sb.append(" persistent: " + this.isPersistent());
final StringBuilder sb = new StringBuilder(1200);
sb.append(superToString());
sb.append(" ssoid: ").append(getSsoId());
sb.append(" userName: ").append(getUserName());
sb.append(" version: ").append(getVersion());
sb.append(" persistent: ").append(isPersistent());
return sb.toString();
}

Expand Down

0 comments on commit 9e59979

Please sign in to comment.