Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EventPropertiesStorage {

EventPropertiesStorage() {
eventName = "";
eventType = "";
eventLatency = EventLatency.Normal;
eventPersistence = EventPersistence.Normal;
eventPopSample = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,17 @@ public void requestException() throws java.io.IOException, PackageManager.NameNo
}
}

@Test
public void newEventPropertiesStorageEventTypeDefaultsToEmptyString() {
// Regression test for #1329: EventPropertiesStorage previously left
// eventType uninitialized (null), so EventProperties.getType() (which
// returns mStorage.eventType) returned null instead of its documented
// "" default. Exercise the pure-Java storage directly: constructing an
// EventProperties here would call setName() -> native validateEventName(),
// which is not loaded in these JVM (MockitoJUnitRunner) unit tests.
EventPropertiesStorage storage = new EventPropertiesStorage();
assertNotNull(storage.eventType);
assertEquals("", storage.eventType);
}

}
13 changes: 11 additions & 2 deletions lib/jni/JniConvertors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,17 @@ EventProperties GetEventProperties(JNIEnv* env, const jstring& jstrEventName, co
const jobjectArray& jEventPropertyStringKeyArray, const jobjectArray& jEventPropertyValueArray) {
EventProperties eventProperties;
eventProperties.SetName(JStringToStdString(env, jstrEventName));
if (jstrEventType != NULL)
eventProperties.SetType(JStringToStdString(env, jstrEventType));
if (jstrEventType != NULL) {
// An empty type means "unset" (the native default). Before #1329 the
// Java getType() returned null for a default EventProperties, so this
// branch was skipped. getType() now returns "" to fix a Java-side NPE;
// forwarding SetType("") here would fail native event-name validation
// and broadcast a spurious EVT_REJECTED for every typeless event, so
// only set a non-empty type.
std::string eventType = JStringToStdString(env, jstrEventType);
if (!eventType.empty())
eventProperties.SetType(eventType);
}
eventProperties.SetLatency(static_cast<EventLatency>(jEventLatency));
eventProperties.SetPersistence(static_cast<EventPersistence>(jEventPersistence));
eventProperties.SetPopsample(static_cast<double>(jEventPopSample));
Expand Down
Loading