Skip to content

Commit

Permalink
OF-2644: Do not use getters in Session#toString implementations
Browse files Browse the repository at this point in the history
This prevents stack overflow when the getters use the toString implementation (for example, for debug logging).
  • Loading branch information
guusdk committed Aug 28, 2023
1 parent 5486250 commit 4ede455
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -902,16 +902,16 @@ public String toString()
}
}
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", serverName='" + getServerName() + '\'' +
", isInitialized=" + isInitialized() +
", hasAuthToken=" + (getAuthToken() != null) +
", serverName='" + serverName + '\'' +
", isInitialized=" + initialized +
", hasAuthToken=" + (authToken != null) +
", peer address='" + peerAddress +'\'' +
", presence='" + getPresence().toString() + '\'' +
", presence='" + presence.toString() + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,12 @@ public LocalComponentSession getSession() {
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", serverName='" + getServerName() + '\'' +
", serverName='" + serverName + '\'' +
", defaultSubdomain='" + defaultSubdomain + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ void deliver(Packet packet) throws UnauthorizedException {
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", serverName='" + getServerName() + '\'' +
", serverName='" + serverName + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,14 @@ public String getAvailableStreamFeatures() {
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", authenticationMethod=" + getAuthenticationMethod() +
", localDomain=" + getLocalDomain() +
", defaultIdentity=" + getDefaultIdentity() +
", authenticationMethod=" + authenticationMethod +
", localDomain=" + localDomain +
", defaultIdentity=" + fromDomain +
", validatedDomains=" + validatedDomains.stream().collect( Collectors.joining( ", ", "{", "}")) +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ public Collection<DomainPair> getOutgoingDomainPairs() {
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", authenticationMethod=" + getAuthenticationMethod() +
", authenticationMethod=" + authenticationMethod +
", outgoingDomainPairs=" + getOutgoingDomainPairs().stream().map( DomainPair::toString ).collect(Collectors.joining(", ", "{", "}")) +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LocalServerSession extends LocalSession implements ServerSession {
/**
* The method that was used to authenticate this session. Null when the session is not authenticated.
*/
private AuthenticationMethod authenticationMethod = null;
protected AuthenticationMethod authenticationMethod = null;

public LocalServerSession(String serverName, Connection connection,
StreamID streamID) {
Expand Down Expand Up @@ -127,12 +127,12 @@ public void setAuthenticationMethod(@Nonnull final AuthenticationMethod authenti
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", isUsingServerDialback=" + isUsingServerDialback() +
", authenticationMethod=" + authenticationMethod +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public abstract class LocalSession implements Session {
/**
* The Address this session is authenticated as.
*/
private JID address;
protected JID address;

/**
* The stream id for this session (random and unique).
*/
private StreamID streamID;
protected final StreamID streamID;

/**
* The current session status.
Expand All @@ -78,9 +79,9 @@ public abstract class LocalSession implements Session {

protected SessionManager sessionManager;

private String serverName;
protected final String serverName;

private long startDate = System.currentTimeMillis();
protected final long startDate = System.currentTimeMillis();

private long lastActiveDate;

Expand Down Expand Up @@ -243,6 +244,7 @@ public Connection getConnection() {
*/
@Override
public Status getStatus() {
System.out.println("This session " + this + " was asked to provide its status, which is " + this.status);
return status;
}

Expand Down Expand Up @@ -533,13 +535,13 @@ public String getHostName() throws UnknownHostException {
@Override
public String toString()
{
return this.getClass().getSimpleName() +"{" +
"address=" + getAddress() +
", streamID=" + getStreamID() +
", status=" + getStatus() +
return this.getClass().getSimpleName() + "{" +
"address=" + address +
", streamID=" + streamID +
", status=" + status +
", isEncrypted=" + isEncrypted() +
", isDetached=" + isDetached() +
", serverName='" + getServerName() + '\'' +
", serverName='" + serverName + '\'' +
'}';
}

Expand Down

0 comments on commit 4ede455

Please sign in to comment.