← 输入框|github.com|刷新
Skip to content

fix(event): omit non-finite event tags from conversion events - #646

Open
Alex Castillo González (pcbeingused33) wants to merge 1 commit into
optimizely:masterfrom
pcbeingused33:fix/non-finite-event-tags
Open

Alex Castillo González (pcbeingused33) wants to merge 1 commit into
optimizely:masterfrom
pcbeingused33:fix/non-finite-event-tags

Conversation

@pcbeingused33

Copy link
Copy Markdown

Summary

track() copies the caller's event tags into the conversion event unchanged. A tag whose value is Double.NaN or ±Infinity (under any key other than the reserved value) has no JSON representation, and GsonSerializer and JsonSerializer (org.json) throw on it (IllegalArgumentException / JSONException). With AsyncHttpEventHandler that exception is raised when the log event body is built on the dispatcher thread, where only IOException and URISyntaxException are handled, so the whole batch (up to 10 events, possibly from other users) is lost. This only shows up when Jackson is not on the classpath, because DefaultJsonSerializer prefers Jackson, which writes NaN without throwing.

Root cause

EventFactory.createVisitor(ConversionEvent) calls setTags(conversionEvent.getTags()) with no validation. EventTagUtils.getNumericValue already rejects NaN/Infinity, but only for the reserved value key, and AttributesUtil.isValidNumber does the same for attributes; other event tags had no equivalent check.

Fix

EventFactory now leaves out event tags whose value is a non-finite Double or Float when it builds the conversion event, and logs a warning naming the tag. The caller's map is not modified, and the same map instance is passed through when there is nothing to remove. Finite numbers and all other tag types are unchanged.

Test

EventFactoryTest.createConversionEventOmitsNonFiniteEventTags tracks a conversion with NaN, Double.POSITIVE_INFINITY and Float.NEGATIVE_INFINITY tags next to valid ones and checks that only the valid tags reach the event, that the input map is untouched, and that a default Gson can serialize the resulting batch. It fails before the change and passes after it.

./gradlew :core-api:test --tests 'com.optimizely.ab.event.*'

This change was prepared with the help of an AI coding assistant.

Event tags holding NaN or Infinity were copied into the conversion event as is. Gson and org.json refuse to serialize those values, so the exception surfaced on the dispatcher thread and the whole batch was dropped. Leave such tags out when the event is built, as is already done for the reserved value tag and for attributes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant