The following issues were found
ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java
37 issues
Line: 149
@JRubyMethod(required = 4, optional = 1)
public IRubyObject map(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
if (!fileBuilderContext.isProto3()) throw runtime.newArgumentError("Cannot add a native map field using proto2 syntax.");
RubySymbol messageSym = runtime.newSymbol("message");
IRubyObject name = args[0];
IRubyObject keyType = args[1];
Reported by PMD.
Line: 151
Ruby runtime = context.runtime;
if (!fileBuilderContext.isProto3()) throw runtime.newArgumentError("Cannot add a native map field using proto2 syntax.");
RubySymbol messageSym = runtime.newSymbol("message");
IRubyObject name = args[0];
IRubyObject keyType = args[1];
IRubyObject valueType = args[2];
IRubyObject number = args[3];
Reported by PMD.
Line: 162
// Validate the key type. We can't accept enums, messages, or floats/doubles
// as map keys. (We exclude these explicitly, and the field-descriptor setter
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
Reported by PMD.
Line: 162
// Validate the key type. We can't accept enums, messages, or floats/doubles
// as map keys. (We exclude these explicitly, and the field-descriptor setter
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
Reported by PMD.
Line: 163
// as map keys. (We exclude these explicitly, and the field-descriptor setter
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
Reported by PMD.
Line: 163
// as map keys. (We exclude these explicitly, and the field-descriptor setter
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
Reported by PMD.
Line: 164
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
mapEntryBuilder.setName(builder.getName() + "_MapEntry_" + name.asJavaString());
Reported by PMD.
Line: 164
// below then ensures that the type is one of the remaining valid options.)
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
mapEntryBuilder.setName(builder.getName() + "_MapEntry_" + name.asJavaString());
Reported by PMD.
Line: 165
if (keyType.equals(runtime.newSymbol("float")) ||
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
mapEntryBuilder.setName(builder.getName() + "_MapEntry_" + name.asJavaString());
mapEntryBuilder.getOptionsBuilder().setMapEntry(true);
Reported by PMD.
Line: 166
keyType.equals(runtime.newSymbol("double")) ||
keyType.equals(runtime.newSymbol("enum")) ||
keyType.equals(messageSym))
throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
DescriptorProto.Builder mapEntryBuilder = fileBuilderContext.getNewMessageBuilder();
mapEntryBuilder.setName(builder.getName() + "_MapEntry_" + name.asJavaString());
mapEntryBuilder.getOptionsBuilder().setMapEntry(true);
Reported by PMD.
java/core/src/main/java/com/google/protobuf/MapEntry.java
37 issues
Line: 200
private void checkFieldDescriptor(FieldDescriptor field) {
if (field.getContainingType() != metadata.descriptor) {
throw new RuntimeException(
"Wrong FieldDescriptor \""
+ field.getFullName()
+ "\" used in message \""
+ metadata.descriptor.getFullName());
}
Reported by PMD.
Line: 229
@Override
public int getRepeatedFieldCount(FieldDescriptor field) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public Object getRepeatedField(FieldDescriptor field, int index) {
throw new RuntimeException("There is no repeated field in a map entry message.");
Reported by PMD.
Line: 234
@Override
public Object getRepeatedField(FieldDescriptor field, int index) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public UnknownFieldSet getUnknownFields() {
return UnknownFieldSet.getDefaultInstance();
Reported by PMD.
Line: 315
private void checkFieldDescriptor(FieldDescriptor field) {
if (field.getContainingType() != metadata.descriptor) {
throw new RuntimeException(
"Wrong FieldDescriptor \""
+ field.getFullName()
+ "\" used in message \""
+ metadata.descriptor.getFullName());
}
Reported by PMD.
Line: 330
// This method should be called for message fields and in a MapEntry
// message only the value field can possibly be a message field.
if (field.getNumber() != 2 || field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
throw new RuntimeException("\"" + field.getFullName() + "\" is not a message value field.");
}
return ((Message) value).newBuilderForType();
}
@SuppressWarnings("unchecked")
Reported by PMD.
Line: 372
@Override
public Builder<K, V> setRepeatedField(FieldDescriptor field, int index, Object value) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public Builder<K, V> addRepeatedField(FieldDescriptor field, Object value) {
throw new RuntimeException("There is no repeated field in a map entry message.");
Reported by PMD.
Line: 377
@Override
public Builder<K, V> addRepeatedField(FieldDescriptor field, Object value) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public Builder<K, V> setUnknownFields(UnknownFieldSet unknownFields) {
// Unknown fields are discarded for MapEntry message.
Reported by PMD.
Line: 426
@Override
public int getRepeatedFieldCount(FieldDescriptor field) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public Object getRepeatedField(FieldDescriptor field, int index) {
throw new RuntimeException("There is no repeated field in a map entry message.");
Reported by PMD.
Line: 431
@Override
public Object getRepeatedField(FieldDescriptor field, int index) {
throw new RuntimeException("There is no repeated field in a map entry message.");
}
@Override
public UnknownFieldSet getUnknownFields() {
return UnknownFieldSet.getDefaultInstance();
Reported by PMD.
Line: 337
@SuppressWarnings("unchecked")
@Override
public Builder<K, V> setField(FieldDescriptor field, Object value) {
checkFieldDescriptor(field);
if (field.getNumber() == 1) {
setKey((K) value);
} else {
if (field.getType() == FieldDescriptor.Type.ENUM) {
Reported by PMD.
java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java
36 issues
Line: 49
public class SingleFieldBuilderV3Test {
@Test
public void testBasicUseAndInvalidations() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false);
assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance());
assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance());
Reported by PMD.
Line: 53
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false);
assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance());
assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance());
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
Reported by PMD.
Line: 54
SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder, TestAllTypesOrBuilder> builder =
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false);
assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance());
assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance());
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
TestAllTypes message = builder.build();
Reported by PMD.
Line: 55
new SingleFieldBuilderV3<>(TestAllTypes.getDefaultInstance(), mockParent, false);
assertThat(builder.getMessage()).isSameInstanceAs(TestAllTypes.getDefaultInstance());
assertThat(builder.getBuilder().buildPartial()).isEqualTo(TestAllTypes.getDefaultInstance());
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
TestAllTypes message = builder.build();
assertThat(message.getOptionalInt32()).isEqualTo(10);
Reported by PMD.
Line: 58
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
TestAllTypes message = builder.build();
assertThat(message.getOptionalInt32()).isEqualTo(10);
// Test that we receive invalidations now that build has been called.
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
Reported by PMD.
Line: 60
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
TestAllTypes message = builder.build();
assertThat(message.getOptionalInt32()).isEqualTo(10);
// Test that we receive invalidations now that build has been called.
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(20);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
Reported by PMD.
Line: 60
builder.getBuilder().setOptionalInt32(10);
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
TestAllTypes message = builder.build();
assertThat(message.getOptionalInt32()).isEqualTo(10);
// Test that we receive invalidations now that build has been called.
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(20);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
Reported by PMD.
Line: 63
assertThat(message.getOptionalInt32()).isEqualTo(10);
// Test that we receive invalidations now that build has been called.
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(20);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
// Test that we don't keep getting invalidations on every change
builder.getBuilder().setOptionalInt32(30);
Reported by PMD.
Line: 65
// Test that we receive invalidations now that build has been called.
assertThat(mockParent.getInvalidationCount()).isEqualTo(0);
builder.getBuilder().setOptionalInt32(20);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
// Test that we don't keep getting invalidations on every change
builder.getBuilder().setOptionalInt32(30);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
}
Reported by PMD.
Line: 69
// Test that we don't keep getting invalidations on every change
builder.getBuilder().setOptionalInt32(30);
assertThat(mockParent.getInvalidationCount()).isEqualTo(1);
}
@Test
public void testSetMessage() {
TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
Reported by PMD.
conformance/binary_json_conformance_suite.cc
36 issues
Line: 387
Column: 23
CWE codes:
120
case ConformanceResponse::kProtobufPayload: {
if (requested_output != conformance::PROTOBUF) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided PROTOBUF instead.")
.c_str());
return false;
}
Reported by FlawFinder.
Line: 406
Column: 23
CWE codes:
120
case ConformanceResponse::kJsonPayload: {
if (requested_output != conformance::JSON) {
ReportFailure(test_name, level, request, response,
StrCat("Test was asked for ",
WireFormatToString(requested_output),
" output but provided JSON instead.")
.c_str());
return false;
}
Reported by FlawFinder.
Line: 443
Column: 32
CWE codes:
120
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
setting.ConformanceLevelToString(level),
(is_proto3 ? ".Proto3" : ".Proto2"), ".ProtobufInput.", test_name);
RunTest(effective_test_name, request, &response);
if (response.result_case() == ConformanceResponse::kParseError) {
Reported by FlawFinder.
Line: 574
Column: 7
CWE codes:
120
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name =
StrCat(setting.ConformanceLevelToString(level),
is_proto3 ? ".Proto3.JsonInput." : ".Proto2.JsonInput.",
test_name, ".Validator");
RunTest(effective_test_name, request, &response);
Reported by FlawFinder.
Line: 618
Column: 32
CWE codes:
120
prototype, test_name, input_json);
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
setting.ConformanceLevelToString(level), ".Proto3.JsonInput.", test_name);
RunTest(effective_test_name, request, &response);
if (response.result_case() == ConformanceResponse::kParseError) {
ReportSuccess(effective_test_name);
Reported by FlawFinder.
Line: 645
Column: 32
CWE codes:
120
prototype, test_name, payload_message.SerializeAsString());
const ConformanceRequest& request = setting.GetRequest();
ConformanceResponse response;
string effective_test_name = StrCat(
setting.ConformanceLevelToString(level), ".", test_name, ".JsonOutput");
RunTest(effective_test_name, request, &response);
if (response.result_case() == ConformanceResponse::kSerializeError) {
ReportSuccess(effective_test_name);
Reported by FlawFinder.
Line: 771
Column: 11
CWE codes:
120
string text = test_message->DebugString();
RunValidProtobufTest(
StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED,
proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataScalarBinary", type_name, "[", i, "]"),
RECOMMENDED, proto, expected_proto, is_proto3);
}
Reported by FlawFinder.
Line: 774
Column: 11
CWE codes:
120
StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED,
proto, text, is_proto3);
RunValidBinaryProtobufTest(
StrCat("ValidDataScalarBinary", type_name, "[", i, "]"),
RECOMMENDED, proto, expected_proto, is_proto3);
}
// Test repeated data for singular fields.
// For scalar message fields, repeated values are merged, which is tested
Reported by FlawFinder.
Line: 855
Column: 11
CWE codes:
120
// Ensures both packed and unpacked data can be parsed.
RunValidProtobufTest(
StrCat("ValidDataRepeated", type_name, ".UnpackedInput"),
REQUIRED, default_proto_unpacked, text, is_proto3);
RunValidProtobufTest(
StrCat("ValidDataRepeated", type_name, ".PackedInput"),
REQUIRED, default_proto_packed, text, is_proto3);
Reported by FlawFinder.
Line: 858
Column: 11
CWE codes:
120
StrCat("ValidDataRepeated", type_name, ".UnpackedInput"),
REQUIRED, default_proto_unpacked, text, is_proto3);
RunValidProtobufTest(
StrCat("ValidDataRepeated", type_name, ".PackedInput"),
REQUIRED, default_proto_packed, text, is_proto3);
// proto2 should encode as unpacked by default and proto3 should encode as
// packed by default.
string expected_proto = rep_field->is_packed()
Reported by FlawFinder.
java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
34 issues
Line: 236
/**
* Checks whether paths in a given fields mask are valid.
*/
public static boolean isValid(Descriptor descriptor, String path) {
String[] parts = path.split(FIELD_SEPARATOR_REGEX);
if (parts.length == 0) {
return false;
}
for (String name : parts) {
Reported by PMD.
Line: 236
/**
* Checks whether paths in a given fields mask are valid.
*/
public static boolean isValid(Descriptor descriptor, String path) {
String[] parts = path.split(FIELD_SEPARATOR_REGEX);
if (parts.length == 0) {
return false;
}
for (String name : parts) {
Reported by PMD.
Line: 53
/**
* Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
*/
public final class FieldMaskUtil {
private static final String FIELD_PATH_SEPARATOR = ",";
private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
private static final String FIELD_SEPARATOR_REGEX = "\\.";
private FieldMaskUtil() {}
Reported by PMD.
Line: 53
/**
* Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
*/
public final class FieldMaskUtil {
private static final String FIELD_PATH_SEPARATOR = ",";
private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
private static final String FIELD_SEPARATOR_REGEX = "\\.";
private FieldMaskUtil() {}
Reported by PMD.
Line: 107
*/
// TODO(xiaofeng): Consider renaming fromStrings()
public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) {
return fromStringList(Internal.getDefaultInstance(type).getDescriptorForType(), paths);
}
/**
* Constructs a FieldMask for a list of field paths in a certain type.
*
Reported by PMD.
Line: 136
}
if (descriptor.isPresent() && !isValid(descriptor.get(), path)) {
throw new IllegalArgumentException(
path + " is not a valid path for " + descriptor.get().getFullName());
}
builder.addPaths(path);
}
return builder.build();
}
Reported by PMD.
Line: 159
*/
public static FieldMask fromFieldNumbers(
Class<? extends Message> type, Iterable<Integer> fieldNumbers) {
Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
FieldMask.Builder builder = FieldMask.newBuilder();
for (Integer fieldNumber : fieldNumbers) {
FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber);
checkArgument(
Reported by PMD.
Line: 167
checkArgument(
field != null,
String.format("%s is not a valid field number for %s.", fieldNumber, type));
builder.addPaths(field.getName());
}
return builder.build();
}
/**
Reported by PMD.
Line: 182
if (path.isEmpty()) {
continue;
}
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
return Joiner.on(FIELD_PATH_SEPARATOR).join(paths);
}
/**
Reported by PMD.
Line: 184
}
paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
}
return Joiner.on(FIELD_PATH_SEPARATOR).join(paths);
}
/**
* Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and
* converting from camel case to snake case.
Reported by PMD.
examples/add_person.py
34 issues
Line: 5
Column: 1
# See README.txt for information and build instructions.
import addressbook_pb2
import sys
try:
raw_input # Python 2
except NameError:
Reported by Pylint.
Line: 31
Column: 5
phone_number = person.phones.add()
phone_number.number = number
type = raw_input("Is this a mobile, home, or work phone? ")
if type == "mobile":
phone_number.type = addressbook_pb2.Person.MOBILE
elif type == "home":
phone_number.type = addressbook_pb2.Person.HOME
elif type == "work":
Reported by Pylint.
Line: 1
Column: 1
#! /usr/bin/env python
# See README.txt for information and build instructions.
import addressbook_pb2
import sys
try:
raw_input # Python 2
Reported by Pylint.
Line: 6
Column: 1
# See README.txt for information and build instructions.
import addressbook_pb2
import sys
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
Reported by Pylint.
Line: 9
Column: 1
import sys
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
# This function fills in a Person message based on user input.
Reported by Pylint.
Line: 11
Column: 1
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
Reported by Pylint.
Line: 15
Column: 1
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
person.name = raw_input("Enter name: ")
email = raw_input("Enter email address (blank for none): ")
if email != "":
Reported by Pylint.
Line: 15
Column: 1
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
person.name = raw_input("Enter name: ")
email = raw_input("Enter email address (blank for none): ")
if email != "":
Reported by Pylint.
Line: 16
Column: 1
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
person.name = raw_input("Enter name: ")
email = raw_input("Enter email address (blank for none): ")
if email != "":
person.email = email
Reported by Pylint.
Line: 17
Column: 1
# This function fills in a Person message based on user input.
def PromptForAddress(person):
person.id = int(raw_input("Enter person ID number: "))
person.name = raw_input("Enter name: ")
email = raw_input("Enter email address (blank for none): ")
if email != "":
person.email = email
Reported by Pylint.
java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java
33 issues
Line: 44
public class WrappersLiteOfMethodTest {
@Test
public void testOf() throws Exception {
TopLevelMessage.Builder builder = TopLevelMessage.newBuilder();
builder.setFieldDouble(DoubleValue.of(2.333));
builder.setFieldFloat(FloatValue.of(2.333f));
builder.setFieldInt32(Int32Value.of(2333));
builder.setFieldInt64(Int64Value.of(23333333333333L));
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java
33 issues
Line: 44
public class WrappersOfMethodTest {
@Test
public void testOf() throws Exception {
TopLevelMessage.Builder builder = TopLevelMessage.newBuilder();
builder.setFieldDouble(DoubleValue.of(2.333));
builder.setFieldFloat(FloatValue.of(2.333f));
builder.setFieldInt32(Int32Value.of(2333));
builder.setFieldInt64(Int64Value.of(23333333333333L));
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 57
builder.setFieldBytes(BytesValue.of(ByteString.wrap("233".getBytes(Internal.UTF_8))));
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 58
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
Line: 59
TopLevelMessage message = builder.build();
assertThat(message.getFieldDouble().getValue()).isEqualTo(2.333);
assertThat(message.getFieldFloat().getValue()).isEqualTo(2.333F);
assertThat(message.getFieldInt32().getValue()).isEqualTo(2333);
assertThat(message.getFieldInt64().getValue()).isEqualTo(23333333333333L);
assertThat(message.getFieldUint32().getValue()).isEqualTo(2333);
assertThat(message.getFieldUint64().getValue()).isEqualTo(23333333333333L);
assertThat(true).isSameInstanceAs(message.getFieldBool().getValue());
assertThat(message.getFieldString().getValue().equals("23333")).isTrue();
Reported by PMD.
java/core/src/main/java/com/google/protobuf/DynamicMessage.java
33 issues
Line: 31
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf;
import static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
Reported by PMD.
Line: 51
*
* @author kenton@google.com Kenton Varda
*/
public final class DynamicMessage extends AbstractMessage {
private final Descriptor type;
private final FieldSet<FieldDescriptor> fields;
private final FieldDescriptor[] oneofCases;
private final UnknownFieldSet unknownFields;
private int memoizedSize = -1;
Reported by PMD.
Line: 52
* @author kenton@google.com Kenton Varda
*/
public final class DynamicMessage extends AbstractMessage {
private final Descriptor type;
private final FieldSet<FieldDescriptor> fields;
private final FieldDescriptor[] oneofCases;
private final UnknownFieldSet unknownFields;
private int memoizedSize = -1;
Reported by PMD.
Line: 53
*/
public final class DynamicMessage extends AbstractMessage {
private final Descriptor type;
private final FieldSet<FieldDescriptor> fields;
private final FieldDescriptor[] oneofCases;
private final UnknownFieldSet unknownFields;
private int memoizedSize = -1;
/**
Reported by PMD.
Line: 54
public final class DynamicMessage extends AbstractMessage {
private final Descriptor type;
private final FieldSet<FieldDescriptor> fields;
private final FieldDescriptor[] oneofCases;
private final UnknownFieldSet unknownFields;
private int memoizedSize = -1;
/**
* Construct a {@code DynamicMessage} using the given {@code FieldSet}. oneofCases stores the
Reported by PMD.
Line: 56
private final FieldSet<FieldDescriptor> fields;
private final FieldDescriptor[] oneofCases;
private final UnknownFieldSet unknownFields;
private int memoizedSize = -1;
/**
* Construct a {@code DynamicMessage} using the given {@code FieldSet}. oneofCases stores the
* FieldDescriptor for each oneof to indicate which field is set. Caller should make sure the
* array is immutable.
Reported by PMD.
Line: 69
DynamicMessage(
Descriptor type,
FieldSet<FieldDescriptor> fields,
FieldDescriptor[] oneofCases,
UnknownFieldSet unknownFields) {
this.type = type;
this.fields = fields;
this.oneofCases = oneofCases;
this.unknownFields = unknownFields;
Reported by PMD.
Line: 79
/** Get a {@code DynamicMessage} representing the default instance of the given type. */
public static DynamicMessage getDefaultInstance(Descriptor type) {
int oneofDeclCount = type.toProto().getOneofDeclCount();
FieldDescriptor[] oneofCases = new FieldDescriptor[oneofDeclCount];
return new DynamicMessage(
type,
FieldSet.<FieldDescriptor>emptySet(),
oneofCases,
Reported by PMD.
Line: 174
public boolean hasOneof(OneofDescriptor oneof) {
verifyOneofContainingType(oneof);
FieldDescriptor field = oneofCases[oneof.getIndex()];
if (field == null) {
return false;
}
return true;
}
Reported by PMD.
Line: 229
// Check that all required fields are present.
for (final FieldDescriptor field : type.getFields()) {
if (field.isRequired()) {
if (!fields.hasField(field)) {
return false;
}
}
}
Reported by PMD.
java/core/src/main/java/com/google/protobuf/Internal.java
32 issues
Line: 63
/** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */
static <T> T checkNotNull(T obj) {
if (obj == null) {
throw new NullPointerException();
}
return obj;
}
/** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */
Reported by PMD.
Line: 71
/** Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. */
static <T> T checkNotNull(T obj, String message) {
if (obj == null) {
throw new NullPointerException(message);
}
return obj;
}
/**
Reported by PMD.
Line: 368
Method method = clazz.getMethod("getDefaultInstance");
return (T) method.invoke(method);
} catch (Exception e) {
throw new RuntimeException("Failed to get default instance for " + clazz, e);
}
}
/** An empty byte array constant used in generated code. */
Reported by PMD.
Line: 296
}
/** Helper method for continuously hashing bytes. */
static int partialHash(int h, byte[] bytes, int offset, int length) {
for (int i = offset; i < offset + length; i++) {
h = h * 31 + bytes[i];
}
return h;
}
Reported by PMD.
Line: 31
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.protobuf;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.AbstractList;
Reported by PMD.
Line: 53
*
* @author kenton@google.com (Kenton Varda)
*/
public final class Internal {
private Internal() {}
static final Charset UTF_8 = Charset.forName("UTF-8");
static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
Reported by PMD.
Line: 53
*
* @author kenton@google.com (Kenton Varda)
*/
public final class Internal {
private Internal() {}
static final Charset UTF_8 = Charset.forName("UTF-8");
static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
Reported by PMD.
Line: 141
ByteBuffer temp = source.duplicate();
// We want to copy all the data in the source ByteBuffer, not just the
// remaining bytes.
temp.clear();
ByteBuffer result = ByteBuffer.allocate(temp.capacity());
result.put(temp);
result.clear();
return result;
}
Reported by PMD.
Line: 142
// We want to copy all the data in the source ByteBuffer, not just the
// remaining bytes.
temp.clear();
ByteBuffer result = ByteBuffer.allocate(temp.capacity());
result.put(temp);
result.clear();
return result;
}
Reported by PMD.
Line: 143
// remaining bytes.
temp.clear();
ByteBuffer result = ByteBuffer.allocate(temp.capacity());
result.put(temp);
result.clear();
return result;
}
/**
Reported by PMD.