Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-30333 use direct references instead of WeakReference, added c… #62

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/main/java/hudson/plugins/jira/JiraSite.java
Expand Up @@ -22,7 +22,6 @@
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -139,7 +138,7 @@ public class JiraSite extends AbstractDescribableImpl<JiraSite> {
*/
private transient Lock projectUpdateLock = new ReentrantLock();

private transient ThreadLocal<WeakReference<JiraSession>> jiraSession = new ThreadLocal<WeakReference<JiraSession>>();
private transient JiraSession jiraSession = null;

@DataBoundConstructor
public JiraSite(URL url, URL alternativeUrl, String userName, String password, boolean supportsWikiStyleComment, boolean recordScmChanges, String userPattern,
Expand Down Expand Up @@ -175,14 +174,13 @@ public JiraSite(URL url, URL alternativeUrl, String userName, String password, b
this.groupVisibility = Util.fixEmpty(groupVisibility);
this.roleVisibility = Util.fixEmpty(roleVisibility);
this.useHTTPAuth = useHTTPAuth;
this.jiraSession.set(new WeakReference<JiraSession>(null));
this.jiraSession = null;
}

protected Object readResolve() {
projectUpdateLock = new ReentrantLock();
issueCache = makeIssueCache();
jiraSession = new ThreadLocal<WeakReference<JiraSession>>();
jiraSession.set(new WeakReference<JiraSession>(null));
jiraSession = null;
return this;
}

Expand All @@ -203,16 +201,11 @@ public String getName() {
*/
@Nullable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it's not nullable any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still nullable, as the called createSession is also nullable. (on null user and password)

public JiraSession getSession() throws IOException {
JiraSession session = null;

if (session == null) {
// TODO: we should check for session timeout, too
// Currently no real problem, as we're using a weak reference for the session, so it will be GC'ed very quickly
session = createSession();
jiraSession.set(new WeakReference<JiraSession>(session));
if (jiraSession == null) {
jiraSession = createSession();
}

return session;
return jiraSession;
}

/**
Expand All @@ -231,6 +224,7 @@ protected JiraSession createSession() throws IOException {
LOGGER.warning("convert URL to URI error: " + e.getMessage());
throw new RuntimeException("failed to create JiraSession due to convert URI error");
}
LOGGER.info("creating Jira Session: " + uri);

final JiraRestClient jiraRestClient = new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(uri, userName, password);
Expand Down