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

Fix Nginx Collect validateParams function NPE #1442

Merged
merged 1 commit into from
Dec 24, 2023

Conversation

Clownsw
Copy link
Contributor

@Clownsw Clownsw commented Dec 24, 2023

What's changed?

Fix Nginx Collect validateParams function NPE

Checklist

  • I hereby agree to the terms of the HertzBeat CLA
  • I have read the Contributing Guide
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Signed-off-by: Clownsw <msmliexx1@gmail.com>
@tomsun28 tomsun28 added enhancement New feature or request good first pull request Good for newcomers bugfix labels Dec 24, 2023
@tomsun28 tomsun28 added this to the 1.4.4 milestone Dec 24, 2023
@a-little-fool
Copy link
Contributor

Why did the previous one report a null pointer? I saw that nginxProtocol==null was used to determine first, so I don't think it will be reported. Perhaps I don't quite understand, and I would like to ask for your clarification

@Clownsw
Copy link
Contributor Author

Clownsw commented Dec 24, 2023

Why did the previous one report a null pointer? I saw that nginxProtocol==null was used to determine first, so I don't think it will be reported. Perhaps I don't quite understand, and I would like to ask for your clarification

 NginxProtocol nginxProtocol = metrics.getNginx(); // Here metrics have been used, So the following judgment has no effect
 if (metrics == null || nginxProtocol == null || nginxProtocol.isInValid()) {

@Clownsw
Copy link
Contributor Author

Clownsw commented Dec 24, 2023

Why did the previous one report a null pointer? I saw that nginxProtocol==null was used to determine first, so I don't think it will be reported. Perhaps I don't quite understand, and I would like to ask for your clarification

use old code test:

Metrics metrics = null;
NginxProtocol nginxProtocol = metrics.getNginx(); // NPE
if (metrics == null || nginxProtocol == null || nginxProtocol.isInValid()) {}

@Clownsw
Copy link
Contributor Author

Clownsw commented Dec 24, 2023

Why did the previous one report a null pointer? I saw that nginxProtocol==null was used to determine first, so I don't think it will be reported. Perhaps I don't quite understand, and I would like to ask for your clarification

 NginxProtocol nginxProtocol = metrics.getNginx(); // Here metrics have been used, So the following judgment has no effect
 if (metrics == null || nginxProtocol == null || nginxProtocol.isInValid()) {

use new code test:

Metrics metrics = null;
final NginxProtocol nginxProtocol;
if (metrics == null || (nginxProtocol = metrics.getNginx()) == null || nginxProtocol.isInValid()) {}
// Success

@a-little-fool
Copy link
Contributor

为什么上一篇报空指针?我看到先用nginxProtocol==null来判断,所以我想不会报错。可能我不太明白,想请教您

 NginxProtocol nginxProtocol = metrics.getNginx(); // Here metrics have been used, So the following judgment has no effect
 if (metrics == null || nginxProtocol == null || nginxProtocol.isInValid()) {

使用新代码测试:

Metrics metrics = null;
final NginxProtocol nginxProtocol;
if (metrics == null || (nginxProtocol = metrics.getNginx()) == null || nginxProtocol.isInValid()) {}
// Success

I see, I didn't notice that. Thank you for pointing it out!LGTM!

Copy link
Contributor

@a-little-fool a-little-fool left a comment

Choose a reason for hiding this comment

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

LGTM!

@a-little-fool a-little-fool merged commit ea77b05 into apache:master Dec 24, 2023
2 checks passed
tomsun28 pushed a commit that referenced this pull request Jan 16, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 9, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 9, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 10, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 10, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 11, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 11, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 11, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
tomsun28 pushed a commit that referenced this pull request Mar 11, 2024
Signed-off-by: Clownsw <msmliexx1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix enhancement New feature or request good first pull request Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants