Skip to content
Merged
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
36 changes: 36 additions & 0 deletions java/tests/junittests/NullParameterEdgeCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,40 @@ void messageRouterConfigWithNullFunctionNamesDoesNotThrowOnCreate() {
assertDoesNotThrow(() -> router[0] = CefMessageRouter.create(config));
if (router[0] != null) router[0].dispose();
}

// Regression tests for issue #21's remaining call sites: a non-null but
// empty Java String reaches the same CEF-internal CHECK(!x.empty()) a
// null string does (the null-vs-empty distinction only matters on the
// JNI marshaling side, not to CEF itself). N_SetURL and the request
// N_SetHeaderByName's name param already got this guard in an earlier
// fix; these four remaining call sites (CefPostDataElement's
// N_SetToFile, CefRequest's N_SetMethod/N_Set, CefResponse's
// N_SetHeaderByName) previously only guarded the null case, not empty.
@Test
void postDataElementSetToFileWithEmptyStringDoesNotThrow() {
CefPostDataElement element = CefPostDataElement.create();
assertDoesNotThrow(() -> element.setToFile(""));
element.dispose();
}

@Test
void requestSetMethodWithEmptyStringDoesNotThrow() {
CefRequest request = CefRequest.create();
assertDoesNotThrow(() -> request.setMethod(""));
request.dispose();
}

@Test
void requestSetWithEmptyUrlAndMethodDoesNotThrow() {
CefRequest request = CefRequest.create();
assertDoesNotThrow(() -> request.set("", "", null, null));
request.dispose();
}

@Test
void responseSetHeaderByNameWithEmptyNameDoesNotThrow() {
CefResponse response = CefResponse.create();
assertDoesNotThrow(() -> response.setHeaderByName("", "value", true));
response.dispose();
}
}
9 changes: 8 additions & 1 deletion native/CefPostDataElement_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ Java_org_cef_network_CefPostDataElement_1N_N_1SetToFile(JNIEnv* env,
// string.
if (!jfilename)
return;
dataElement->SetToFile(GetJNIString(env, jfilename));
// A non-null but empty Java string reaches the same DCHECK -- CEF's own
// CHECK(!fileName.empty()) aborts the Debug/coverage build (silently
// permitted in Release). See Thrameos/java-cef#20/#21 and
// CefRequest_N.cpp's matching guard.
CefString fileName = GetJNIString(env, jfilename);
if (fileName.empty())
return;
dataElement->SetToFile(fileName);
}

JNIEXPORT void JNICALL
Expand Down
20 changes: 17 additions & 3 deletions native/CefRequest_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ Java_org_cef_network_CefRequest_1N_N_1SetMethod(JNIEnv* env,
// string rather than passing through an empty CefString.
if (!jmethod)
return;
request->SetMethod(GetJNIString(env, jmethod));
// A non-null but empty Java string reaches the same DCHECK -- CEF's own
// CHECK(!method.empty()) aborts the Debug/coverage build (silently
// permitted in Release). See Thrameos/java-cef#21.
CefString method = GetJNIString(env, jmethod);
if (method.empty())
return;
request->SetMethod(method);
}

JNIEXPORT jobject JNICALL
Expand Down Expand Up @@ -326,9 +332,17 @@ Java_org_cef_network_CefRequest_1N_N_1Set(JNIEnv* env,
// being empty right after), so skip the call entirely for a null Java
// string -- the SetHeaderMap() call above has no such restriction and
// should still happen regardless.
//
// A non-null but empty Java string reaches the same DCHECK -- CEF's own
// CHECK(!url.empty())/CHECK(!method.empty()) abort the Debug/coverage
// build (silently permitted in Release). See Thrameos/java-cef#21 and
// this file's other matching guards.
if (jurl && jmethod) {
request->Set(GetJNIString(env, jurl), GetJNIString(env, jmethod),
postDataObj.GetCefObject(), headerMap);
CefString url = GetJNIString(env, jurl);
CefString method = GetJNIString(env, jmethod);
if (!url.empty() && !method.empty()) {
request->Set(url, method, postDataObj.GetCefObject(), headerMap);
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions native/CefResponse_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@ Java_org_cef_network_CefResponse_1N_N_1SetHeaderByName(JNIEnv* env,
// name.
if (!jname)
return;
return response->SetHeaderByName(GetJNIString(env, jname),
GetJNIString(env, jvalue),
// A non-null but empty Java name reaches the same DCHECK -- CEF's own
// CHECK(!name.empty()) aborts the Debug/coverage build (silently
// permitted in Release). See Thrameos/java-cef#19/#20/#21 and
// CefRequest_N.cpp's matching guard.
CefString name = GetJNIString(env, jname);
if (name.empty())
return;
return response->SetHeaderByName(name, GetJNIString(env, jvalue),
joverride != JNI_FALSE);
}

Expand Down
Loading