Skip to content

Add NPE check for PulsarService#getAdminClient - #9782

Merged
codelipenghui merged 3 commits into
apache:masterfrom
BewareMyPower:bewaremypower/check-npe
Mar 5, 2021
Merged

codelipenghui merged 3 commits into
apache:masterfrom
BewareMyPower:bewaremypower/check-npe

Conversation

@BewareMyPower

@BewareMyPower BewareMyPower commented Mar 3, 2021 •

Copy link
Copy Markdown
Contributor

Motivation

If user set incorrect brokerClientTlsEnabled config, the PulsarService#getAdminClient would throw NPE and the error logs is not clear. For example, start a standalone pulsar with brokerClientTlsEnabled=true, some admin APIs that don't involve PulsarService#getAdminClient work well, however some admin APIs like GET /admin/v2/non-persistent/:tenant/:namespace will throw NPE with following logs:

org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)

After this PR, the logs became:

org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080

Modifications

  • Check if adminApiUrl is null in PulsarService#getAdminClient and give a human readable error message.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

I like we are fixing this kind of issues.

Users must never face an NPE, it is really something that is perceived as poor quality.

thank you @BewareMyPower

@zymap
zymap requested review from codelipenghui and merlimat March 3, 2021 10:54
@zymap zymap added area/broker type/bug The PR fixed a bug or issue reported a bug labels Mar 3, 2021
@zymap zymap added this to the 2.8.0 milestone Mar 3, 2021
@BewareMyPower

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@BewareMyPower

Copy link
Copy Markdown
Contributor Author

/pulsarbot run-failure-checks

@wolfstudy

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

@codelipenghui
codelipenghui merged commit c97ebb0 into apache:master Mar 5, 2021
lhotari added a commit to lhotari/pulsar that referenced this pull request Mar 5, 2021
### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
mlyahmed pushed a commit to mlyahmed/pulsar that referenced this pull request Mar 5, 2021
### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
merlimat pushed a commit that referenced this pull request Mar 5, 2021
### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
mlyahmed pushed a commit to mlyahmed/pulsar that referenced this pull request Mar 7, 2021
…9746)

### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.
@BewareMyPower
BewareMyPower deleted the bewaremypower/check-npe branch March 22, 2021 08:14
@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Mar 23, 2021
codelipenghui pushed a commit that referenced this pull request Mar 23, 2021
### Motivation

If user set incorrect `brokerClientTlsEnabled` config, the `PulsarService#getAdminClient` would throw NPE and the error logs is not clear. For example, start a standalone pulsar with `brokerClientTlsEnabled=true`, some admin APIs that don't involve `PulsarService#getAdminClient` work well, however some admin APIs like `GET /admin/v2/non-persistent/:tenant/:namespace` will throw NPE with following logs:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.NullPointerException
	at org.apache.pulsar.broker.PulsarService.getAdminClient(PulsarService.java:1193)
	at org.apache.pulsar.broker.admin.v2.NonPersistentTopics.getList(NonPersistentTopics.java:273)
```

After this PR, the logs became:

```
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: adminApiUrl is null, isBrokerClientTlsEnabled: true, webServiceAddressTls: null, webServiceAddress: http://localhost:8080
```

### Modifications

- Check if `adminApiUrl` is null in `PulsarService#getAdminClient` and give a human readable error message.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

(cherry picked from commit c97ebb0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/broker cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.2 type/bug The PR fixed a bug or issue reported a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants