Assign the results of getClass() calls to unused variables

This works around a ReturnValueIgnored errorprone issue. There were several other places where this was already done, this is just catching up the remaining two places.

PiperOrigin-RevId: 671878499
pull/18145/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent b35d4bad3c
commit dfd7784fa1
  1. 3
      src/google/protobuf/compiler/java/lite/enum_field.cc
  2. 3
      src/google/protobuf/compiler/java/lite/message_field.cc

@ -111,7 +111,8 @@ void SetEnumVariables(
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["null_check"] = "value.getClass();\n";
(*variables)["null_check"] =
"java.lang.Class<?> unusedValueClass = value.getClass();\n";
// Calls to Annotate() use variable ranges to know which text to annotate.
(*variables)["{"] = "";
(*variables)["}"] = "";

@ -88,7 +88,8 @@ void SetMessageVariables(
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["null_check"] = "value.getClass();\n";
(*variables)["null_check"] =
"java.lang.Class<?> unusedValueClass = value.getClass();\n";
// Annotations often use { and } to determine ranges.
(*variables)["{"] = "";
(*variables)["}"] = "";

Loading…
Cancel
Save