Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated code for Android Clusters does not properly handle optional values #18274

Closed
g-coppock opened this issue May 10, 2022 · 0 comments · Fixed by #19237
Closed

Generated code for Android Clusters does not properly handle optional values #18274

g-coppock opened this issue May 10, 2022 · 0 comments · Fixed by #19237

Comments

@g-coppock
Copy link
Contributor

Problem

In the generated cluster code (e.g. NetworkCommissioningClient-InvokeSubscribeImpl.cpp), an Optional<Long> is passed as an argument for the breadcrumb attribute for the generated cluster commands (e.g. addOrUpdateWiFiNetwork).

The generated code looks like:

if (breadcrumb != nullptr) {
    jobject optionalValue_0;
    chip::JniReferences::GetInstance().GetOptionalValue(breadcrumb, optionalValue_0);
    auto & definedValue_0 = request.breadcrumb.Emplace();
    definedValue_0 = static_cast<std::remove_reference_t<decltype(definedValue_0)>>(chip::JniReferences::GetInstance().LongToPrimitive(optionalValue_0));
}

However, this fails with a JNI error on the call to LongToPrimitive, as the optionalValue_0 (the unwrapped value from the Optional) may be null.

The generating code is here:
https://github.com/project-chip/connectedhomeip/blob/master/scripts/idl/generators/java/ChipClustersCpp.jinja

Proposed Solution

The generated code should probably look like:

if (breadcrumb != nullptr) {
    jobject optionalValue_0;
    chip::JniReferences::GetInstance().GetOptionalValue(breadcrumb, optionalValue_0);
    if (optionalValue_0 != nullptr) {
        auto & definedValue_0 = request.breadcrumb.Emplace();
        definedValue_0 = static_cast<std::remove_reference_t<decltype(definedValue_0)>>(chip::JniReferences::GetInstance().LongToPrimitive(optionalValue_0));
    }
}
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 a pull request may close this issue.

1 participant