Skip to content

Commit

Permalink
guard lettuce npe
Browse files Browse the repository at this point in the history
  • Loading branch information
tbradellis committed Apr 11, 2023
1 parent 3062016 commit c448372
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.Token;

import java.util.logging.Level;

public class NRHolder {
private String segmentName = null;
private Segment segment = null;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void end() {
token.linkAndExpire();
token = null;
}
if (segment != null) {
if (segment != null && params != null) {
String operation = params.getOperation();
if (operation.equalsIgnoreCase("expire")) {
segment.ignore();
Expand All @@ -56,9 +58,14 @@ public void end() {
params = null;
segment = null;
} else {
String operation = params.getOperation();
if (!operation.equalsIgnoreCase("expire")) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
if (params != null) {
String operation = params.getOperation();
if (!operation.equalsIgnoreCase("expire")) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
}
} else {
// Likely the uri was null when NRHolder was created.
NewRelic.getAgent().getLogger().log(Level.WARNING, "DatastoreParameters was null for Lettuce instrumentation. Unable to report as external.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.Token;

import java.util.logging.Level;

public class NRHolder {
private String segmentName = null;
private Segment segment = null;
Expand Down Expand Up @@ -45,7 +47,7 @@ public void end() {
token.linkAndExpire();
token = null;
}
if (segment != null) {
if (segment != null && params != null) {
String operation = params.getOperation();
if (operation.equalsIgnoreCase("expire")) {
segment.ignore();
Expand All @@ -56,9 +58,14 @@ public void end() {
params = null;
segment = null;
} else {
String operation = params.getOperation();
if (!operation.equalsIgnoreCase("expire")) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
if (params != null) {
String operation = params.getOperation();
if (!operation.equalsIgnoreCase("expire")) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
}
} else {
// Likely the uri was null when NRHolder was created.
NewRelic.getAgent().getLogger().log(Level.WARNING, "DatastoreParameters was null for Lettuce instrumentation. Unable to report as external");
}
}
}
Expand Down

0 comments on commit c448372

Please sign in to comment.