Skip to content

java.lang.AssertionError when using HTTP/HTTPS url for the git.uri with -enableassertions flag enabled. #2284

@kvmw

Description

@kvmw

Both FileBasedSshSessionFactory and PropertyBasedSshSessionFactory are expecting at least one ssh URL in the git configuration. So a HTTP/HTTPS URL for git.uri can cause java.lang.AssertionError, if -enableassertions flag is true.

The issue in often not visible because above flag is false by default. But in development or test environment, which the flag might be enabled, one can see the issue.

Sample
Running any sample config-server application with above flag enabled can show the issue.

java -ea -jar ./build/libs/config-server-sample-0.0.1-SNAPSHOT.jar

Possible Solution
FileBasedSshTransportConfigCallback and PropertyBasedSshTransportConfigCallback should configure the SshTransport only if there is at least one SSH URL in the configuration.

current code:

@Override
public void configure(Transport transport) {
  if (transport instanceof SshTransport) {
    ((SshTransport) transport).setSshSessionFactory(new FileBasedSshSessionFactory(
		new SshUriPropertyProcessor(this.sshUriProperties).getSshKeysByHostname()));
  }
}

proposed change:

@Override
public void configure(Transport transport) {
  if (transport instanceof SshTransport) {
        var sshKeysByHostname = new SshUriPropertyProcessor(this.sshUriProperties).getSshKeysByHostname();
        if (!sshKeysByHostname.isEmpty()) {  // Only if the map is not empty
	  ((SshTransport) transport).setSshSessionFactory(new FileBasedSshSessionFactory(sshKeysByHostname));
	}
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions