Skip to content

Commit

Permalink
Fix codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
kfaraz committed Dec 4, 2023
1 parent 74860c7 commit f418435
Showing 1 changed file with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package org.apache.druid.server.audit;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.inject.Inject;
import org.apache.druid.audit.AuditEvent;
import org.apache.druid.audit.AuditManagerConfig;
import org.apache.druid.error.InvalidInput;
import org.apache.druid.guice.annotations.Json;
import org.apache.druid.guice.annotations.JsonNonNull;
import org.apache.druid.java.util.common.StringUtils;
Expand Down Expand Up @@ -75,26 +75,6 @@ public AuditRecord processAuditEvent(AuditEvent event)
);
}

public <T> T deserializePayloadFromString(String serializedPayload, Class<T> clazz)
{
if (serializedPayload == null || serializedPayload.isEmpty()) {
return null;
} else if (serializedPayload.contains(PAYLOAD_TRUNCATED_MSG)) {
throw InvalidInput.exception("Cannot deserialize audit payload[%s].", serializedPayload);
}

try {
return jsonMapper.readValue(serializedPayload, clazz);
}
catch (IOException e) {
throw InvalidInput.exception(
e,
"Could not deserialize audit payload[%s] into class[%s]",
serializedPayload, clazz
);
}
}

private String serializePayloadToString(Object payload)
{
if (payload == null) {
Expand Down Expand Up @@ -123,7 +103,7 @@ private String truncateSerializedAuditPayload(String serializedPayload)
return serializedPayload;
}

int payloadSize = serializedPayload.getBytes().length;
int payloadSize = serializedPayload.getBytes(Charsets.UTF_8).length;
if (payloadSize > config.getMaxPayloadSizeBytes()) {
return PAYLOAD_TRUNCATED_MSG + StringUtils.format("[%s].", config.getMaxPayloadSizeBytes());
} else {
Expand Down

0 comments on commit f418435

Please sign in to comment.