jenkinsci / jenkinsci/subversion-plugin

[JENKINS-23910] NullPointerException in JUnit tests calling postCredential

Open
#1,152 0 comments 0 reactions 0 assignees View on GitHub
component:subversion-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
131
Forks
275
Avg merge
12h 4m
Merged PRs (30d)
6

Description

Hi. This code:

DescriptorExtensionList> desc = SubversionSCM.all();

DescriptorImpl ss = (DescriptorImpl) desc.get(DescriptorImpl.class);

StringWriter log = new StringWriter();

PrintWriter logWriter = new PrintWriter(log);

UserProvidedCredential upc =

new UserProvidedCredential(user, password, null,

request.findAncestorObject(AbstractProject.class));

ss.postCredential(url[0], upc, logWriter);

causes:

Caused by: java.lang.NullPointerException

at hudson.scm.SubversionSCM$DescriptorImpl$1.onSuccess(SubversionSCM.java:2249)

at hudson.scm.UserProvidedCredential$AuthenticationManagerImpl.acknowledgeAuthentication(UserProvidedCredential.java:233)

at org.tmatesoft.svn.core.auth.BasicAuthenticationManager.acknowledgeAuthentication(BasicAuthenticationManager.java:56)

at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection._request(HTTPConnection.java:749)

at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:382)

In:

public void postCredential(String url, final UserProvidedCredential upc, PrintWriter logWriter) throws SVNException, IOException {

SVNRepository repository = null;

try {

// the way it works with SVNKit is that

// 1) svnkit calls AuthenticationManager asking for a credential.

// this is when we can see the 'realm', which identifies the user domain.

// 2) DefaultSVNAuthenticationManager returns the username and password we set below

// 3) if the authentication is successful, svnkit calls back acknowledgeAuthentication

// (so we store the password info here)

repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));

repository.setTunnelProvider( createDefaultSVNOptions() );

AuthenticationManagerImpl authManager = upc.new AuthenticationManagerImpl(logWriter) {

@​Override

protected void onSuccess(String realm, Credential cred)


{
LOGGER.info("Persisted "+cred+" for "+realm);
credentials.put(realm, cred);
save();
if (upc.inContextOf!=null)
new PerJobCredentialStore(upc.inContextOf).acknowledgeAuthentication(realm,cred);

}

};

authManager.setAuthenticationForced(true);

repository.setAuthenticationManager(authManager);

repository.testConnection();

authManager.checkIfProtocolCompleted();

} finally


{
if (repository != null)
repository.closeSession();
}

}

Because:

credentials is null in "credentials.put(realm, cred);" statement.

version 1.54 works fine

---
Originally reported by dmatag, imported from: NullPointerException in JUnit tests calling postCredential


  • status: Open
  • priority: Major
  • component(s): subversion-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251212-090250

Raw content of original issue

Hi. This code:

DescriptorExtensionList<SCM, SCMDescriptor<?>> desc = SubversionSCM.all();
DescriptorImpl ss = (DescriptorImpl) desc.get(DescriptorImpl.class);
StringWriter log = new StringWriter();
PrintWriter logWriter = new PrintWriter(log);
UserProvidedCredential upc =
new UserProvidedCredential(user, password, null,
request.findAncestorObject(AbstractProject.class));

ss.postCredential(url[0], upc, logWriter);

causes:

Caused by: java.lang.NullPointerException
at hudson.scm.SubversionSCM$DescriptorImpl$1.onSuccess(SubversionSCM.java:2249)
at hudson.scm.UserProvidedCredential$AuthenticationManagerImpl.acknowledgeAuthentication(UserProvidedCredential.java:233)
at org.tmatesoft.svn.core.auth.BasicAuthenticationManager.acknowledgeAuthentication(BasicAuthenticationManager.java:56)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection._request(HTTPConnection.java:749)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:382)

In:

public void postCredential(String url, final UserProvidedCredential upc, PrintWriter logWriter) throws SVNException, IOException {
SVNRepository repository = null;

try {
// the way it works with SVNKit is that
// 1) svnkit calls AuthenticationManager asking for a credential.
// this is when we can see the 'realm', which identifies the user domain.
// 2) DefaultSVNAuthenticationManager returns the username and password we set below
// 3) if the authentication is successful, svnkit calls back acknowledgeAuthentication
// (so we store the password info here)
repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
repository.setTunnelProvider( createDefaultSVNOptions() );
AuthenticationManagerImpl authManager = upc.new AuthenticationManagerImpl(logWriter) {
@Override
protected void onSuccess(String realm, Credential cred)


{
LOGGER.info("Persisted "+cred+" for "+realm);
credentials.put(realm, cred);
save();
if (upc.inContextOf!=null)
new PerJobCredentialStore(upc.inContextOf).acknowledgeAuthentication(realm,cred);

}

};
authManager.setAuthenticationForced(true);
repository.setAuthenticationManager(authManager);
repository.testConnection();
authManager.checkIfProtocolCompleted();
} finally


{
if (repository != null)
repository.closeSession();
}

}

Because:
credentials is null in "credentials.put(realm, cred);" statement.

version 1.54 works fine

  • environment: Jenkins 1.572 and lower

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.