Skip to content

Commit 6b41ef6

Browse files
committed
Add null check for enum type
1 parent 1f2f8c2 commit 6b41ef6

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

agent/agent-profiler/agent-alerting-api/src/main/java/com/microsoft/applicationinsights/alerting/aiconfig/AlertingConfig.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public RequestFilter setValue(String value) {
4040
@Override
4141
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
4242
jsonWriter.writeStartObject();
43-
jsonWriter.writeStringField("type", type.name());
43+
if (type != null) {
44+
jsonWriter.writeStringField("type", type.name());
45+
}
4446
jsonWriter.writeStringField("value", value);
4547
jsonWriter.writeEndObject();
4648
return jsonWriter;
@@ -164,7 +166,9 @@ public RequestAggregation setConfiguration(RequestAggregationConfig configuratio
164166
@Override
165167
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
166168
jsonWriter.writeStartObject();
167-
jsonWriter.writeStringField("type", type.name());
169+
if (type != null) {
170+
jsonWriter.writeStringField("type", type.name());
171+
}
168172
jsonWriter.writeLongField("windowSizeMillis", windowSizeMillis);
169173
jsonWriter.writeJsonField("configuration", configuration);
170174
jsonWriter.writeEndObject();
@@ -232,7 +236,9 @@ public RequestTriggerThreshold setValue(float value) {
232236
@Override
233237
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
234238
jsonWriter.writeStartObject();
235-
jsonWriter.writeStringField("type", type.name());
239+
if (type != null) {
240+
jsonWriter.writeStringField("type", type.name());
241+
}
236242
jsonWriter.writeFloatField("value", value);
237243
jsonWriter.writeEndObject();
238244
return jsonWriter;
@@ -290,7 +296,9 @@ public RequestTriggerThrottling setValue(long value) {
290296
@Override
291297
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
292298
jsonWriter.writeStartObject();
293-
jsonWriter.writeStringField("type", type.name());
299+
if (type != null) {
300+
jsonWriter.writeStringField("type", type.name());
301+
}
294302
jsonWriter.writeLongField("value", value);
295303
jsonWriter.writeEndObject();
296304
return jsonWriter;

agent/agent-profiler/agent-alerting-api/src/main/java/com/microsoft/applicationinsights/alerting/alert/AlertBreach.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public abstract static class Builder implements JsonSerializable<Builder> {
118118
@Override
119119
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
120120
jsonWriter.writeStartObject();
121-
jsonWriter.writeStringField("type", type.name());
121+
if (type != null) {
122+
jsonWriter.writeStringField("type", type.name());
123+
}
122124
jsonWriter.writeDoubleField("alertValue", alertValue);
123125
jsonWriter.writeJsonField("alertConfiguration", alertConfiguration);
124126
jsonWriter.writeDoubleField("cpuMetric", cpuMetric);

agent/agent-profiler/agent-alerting-api/src/main/java/com/microsoft/applicationinsights/alerting/config/AlertConfiguration.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public AlertConfiguration setRequestTrigger(AlertingConfig.RequestTrigger reques
6767
@Override
6868
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
6969
jsonWriter.writeStartObject();
70-
jsonWriter.writeStringField("type", type.name());
70+
if (type != null) {
71+
jsonWriter.writeStringField("type", type.name());
72+
}
7173
jsonWriter.writeBooleanField("enabled", enabled);
7274
jsonWriter.writeFloatField("threshold", threshold);
7375
jsonWriter.writeIntField("profileDurationSeconds", profileDurationSeconds);
@@ -113,7 +115,9 @@ public abstract Builder setRequestTrigger(
113115
@Override
114116
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
115117
jsonWriter.writeStartObject();
116-
jsonWriter.writeStringField("type", type.name());
118+
if (type != null) {
119+
jsonWriter.writeStringField("type", type.name());
120+
}
117121
jsonWriter.writeBooleanField("enabled", enabled);
118122
jsonWriter.writeFloatField("threshold", threshold);
119123
jsonWriter.writeIntField("profileDurationSeconds", profileDurationSeconds);

agent/agent-tooling/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies {
4141
implementation("com.azure:azure-identity") {
4242
exclude("org.ow2.asm", "asm")
4343
}
44-
implementation("com.azure:azure-json")
4544

4645
compileOnly("io.opentelemetry:opentelemetry-api-incubator")
4746
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")

0 commit comments

Comments
 (0)