Skip to content

NPE from OkHttpChannelBuilder with ConnectionSpec.CLEARTEXT #1815

@justinsb

Description

@justinsb

I'm getting a NPE when I use OkHttpChannelBuilder with ConnectionSpec.CLEARTEXT. I might be misusing the API, but I think it's actually an issue.

    ConnectionSpec connectionSpec = new ConnectionSpec.Builder(ConnectionSpec.CLEARTEXT).build();

    ManagedChannelImpl channel = OkHttpChannelBuilder.forAddress(host, port).connectionSpec(connectionSpec).build();

The problem is that Utils.convertSpec is calling spec.tlsVersions:

static ConnectionSpec convertSpec(com.squareup.okhttp.ConnectionSpec spec) {
    List<com.squareup.okhttp.TlsVersion> tlsVersionList = spec.tlsVersions();

And spec.tlsVersions assumes tlsVersions is non-null:

  public List<TlsVersion> tlsVersions() {
    TlsVersion[] result = new TlsVersion[tlsVersions.length];

But tlsVersions is always null (and enforced to be so) if not using TLS.

If this isn't me doing something wrong, I'm happy to send a patch. I guess the patch should be to check whether TLS is enabled before calling tlsVersions, in Utils.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions