The following issues were found
java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java
421 issues
Line: 52
/** Unit tests for map fields. */
@RunWith(JUnit4.class)
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
Reported by PMD.
Line: 52
/** Unit tests for map fields. */
@RunWith(JUnit4.class)
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
Line: 55
public final class MapForProto2LiteTest {
private void setMapValues(TestMap.Builder builder) {
builder
.putInt32ToInt32Field(1, 11)
.putInt32ToInt32Field(2, 22)
.putInt32ToInt32Field(3, 33)
.putInt32ToStringField(1, "11")
.putInt32ToStringField(2, "22")
Reported by PMD.
java/core/src/test/java/com/google/protobuf/WireFormatLiteTest.java
352 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.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite;
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 static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite;
Reported by PMD.
Line: 66
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class WireFormatLiteTest {
@Test
public void testSerializeExtensionsLite() throws Exception {
// TestAllTypes and TestAllExtensions should have compatible wire formats,
// so if we serialize a TestAllExtensions then parse it as TestAllTypes
Reported by PMD.
Line: 66
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class WireFormatLiteTest {
@Test
public void testSerializeExtensionsLite() throws Exception {
// TestAllTypes and TestAllExtensions should have compatible wire formats,
// so if we serialize a TestAllExtensions then parse it as TestAllTypes
Reported by PMD.
Line: 66
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class WireFormatLiteTest {
@Test
public void testSerializeExtensionsLite() throws Exception {
// TestAllTypes and TestAllExtensions should have compatible wire formats,
// so if we serialize a TestAllExtensions then parse it as TestAllTypes
Reported by PMD.
Line: 75
// it should work.
TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
Reported by PMD.
Line: 76
TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 76
TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 76
TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet();
ByteString rawBytes = message.toByteString();
assertThat(message.getSerializedSize()).isEqualTo(rawBytes.size());
TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
TestUtil.assertAllFieldsSet(message2);
}
Reported by PMD.
Line: 88
// TestPackedTypes and TestPackedExtensions should have compatible wire
// formats; check that they serialize to the same string.
TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet();
ByteString rawBytes = message.toByteString();
TestPackedTypes message2 = TestUtil.getPackedSet();
ByteString rawBytes2 = message2.toByteString();
assertThat(rawBytes2).isEqualTo(rawBytes);
Reported by PMD.
java/core/src/main/java/com/google/protobuf/TextFormat.java
349 issues
Line: 2139
case MESSAGE:
case GROUP:
throw new RuntimeException("Can't get here.");
}
}
if (field.isRepeated()) {
// TODO(b/29122459): If field.isMapField() and FORBID_SINGULAR_OVERWRITES mode,
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 static java.nio.charset.StandardCharsets.UTF_8;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 59
* @author wenboz@google.com Wenbo Zhu
* @author kenton@google.com Kenton Varda
*/
public final class TextFormat {
private TextFormat() {}
private static final Logger logger = Logger.getLogger(TextFormat.class.getName());
Reported by PMD.
Line: 75
@Deprecated
public static void print(final MessageOrBuilder message, final Appendable output)
throws IOException {
printer().print(message, output);
}
/**
* Outputs a textual representation of {@code fields} to {@code output}.
*
Reported by PMD.
Line: 86
@Deprecated
public static void print(final UnknownFieldSet fields, final Appendable output)
throws IOException {
printer().print(fields, output);
}
/**
* Same as {@code print()}, except that non-ASCII characters are not escaped.
*
Reported by PMD.
java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
334 issues
Line: 53
* Unit tests for protos that doesn't support field presence test for optional non-message fields.
*/
@RunWith(JUnit4.class)
public class FieldPresenceTest {
private static boolean hasMethod(Class<?> clazz, String name) {
try {
if (clazz.getMethod(name) != null) {
return true;
} else {
Reported by PMD.
Line: 56
public class FieldPresenceTest {
private static boolean hasMethod(Class<?> clazz, String name) {
try {
if (clazz.getMethod(name) != null) {
return true;
} else {
return false;
}
} catch (NoSuchMethodException e) {
Reported by PMD.
Line: 68
private static void assertHasMethodRemoved(
Class<?> classWithFieldPresence, Class<?> classWithoutFieldPresence, String camelName) {
assertThat(hasMethod(classWithFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithFieldPresence, "has" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "has" + camelName)).isFalse();
}
Reported by PMD.
Line: 69
private static void assertHasMethodRemoved(
Class<?> classWithFieldPresence, Class<?> classWithoutFieldPresence, String camelName) {
assertThat(hasMethod(classWithFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithFieldPresence, "has" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "has" + camelName)).isFalse();
}
private static void assertHasMethodExisting(Class<?> clazz, String camelName) {
Reported by PMD.
Line: 70
Class<?> classWithFieldPresence, Class<?> classWithoutFieldPresence, String camelName) {
assertThat(hasMethod(classWithFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithFieldPresence, "has" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "has" + camelName)).isFalse();
}
private static void assertHasMethodExisting(Class<?> clazz, String camelName) {
assertThat(hasMethod(clazz, "get" + camelName)).isTrue();
Reported by PMD.
Line: 71
assertThat(hasMethod(classWithFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithFieldPresence, "has" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "get" + camelName)).isTrue();
assertThat(hasMethod(classWithoutFieldPresence, "has" + camelName)).isFalse();
}
private static void assertHasMethodExisting(Class<?> clazz, String camelName) {
assertThat(hasMethod(clazz, "get" + camelName)).isTrue();
assertThat(hasMethod(clazz, "has" + camelName)).isTrue();
Reported by PMD.
Line: 75
}
private static void assertHasMethodExisting(Class<?> clazz, String camelName) {
assertThat(hasMethod(clazz, "get" + camelName)).isTrue();
assertThat(hasMethod(clazz, "has" + camelName)).isTrue();
}
@Test
public void testHasMethod() {
Reported by PMD.
Line: 76
private static void assertHasMethodExisting(Class<?> clazz, String camelName) {
assertThat(hasMethod(clazz, "get" + camelName)).isTrue();
assertThat(hasMethod(clazz, "has" + camelName)).isTrue();
}
@Test
public void testHasMethod() {
// Optional non-message fields don't have a hasFoo() method generated.
Reported by PMD.
Line: 80
}
@Test
public void testHasMethod() {
// Optional non-message fields don't have a hasFoo() method generated.
assertHasMethodRemoved(UnittestProto.TestAllTypes.class, TestAllTypes.class, "OptionalInt32");
assertHasMethodRemoved(UnittestProto.TestAllTypes.class, TestAllTypes.class, "OptionalString");
assertHasMethodRemoved(UnittestProto.TestAllTypes.class, TestAllTypes.class, "OptionalBytes");
assertHasMethodRemoved(
Reported by PMD.
Line: 98
UnittestProto.TestAllTypes.Builder.class, TestAllTypes.Builder.class, "OptionalNestedEnum");
// message fields still have the hasFoo() method generated.
assertThat(TestAllTypes.getDefaultInstance().hasOptionalNestedMessage()).isFalse();
assertThat(TestAllTypes.newBuilder().hasOptionalNestedMessage()).isFalse();
// oneof fields support hasFoo() methods for non-message types.
assertHasMethodExisting(TestAllTypes.class, "OneofUint32");
assertHasMethodExisting(TestAllTypes.class, "OneofString");
Reported by PMD.
python/google/protobuf/internal/unknown_fields_test.py
324 issues
Line: 43
Column: 1
except ImportError:
import unittest
import sys
from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
Reported by Pylint.
Line: 44
Column: 1
import unittest
import sys
from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
from google.protobuf.internal import message_set_extensions_pb2
Reported by Pylint.
Line: 45
Column: 1
import sys
from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import missing_enum_values_pb2
Reported by Pylint.
Line: 46
Column: 1
from google.protobuf import map_unittest_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_pb2
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import missing_enum_values_pb2
from google.protobuf.internal import test_util
Reported by Pylint.
Line: 49
Column: 1
from google.protobuf import unittest_proto3_arena_pb2
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import missing_enum_values_pb2
from google.protobuf.internal import test_util
from google.protobuf.internal import testing_refleaks
from google.protobuf.internal import type_checkers
from google.protobuf.internal import wire_format
Reported by Pylint.
Line: 50
Column: 1
from google.protobuf.internal import api_implementation
from google.protobuf.internal import encoder
from google.protobuf.internal import message_set_extensions_pb2
from google.protobuf.internal import missing_enum_values_pb2
from google.protobuf.internal import test_util
from google.protobuf.internal import testing_refleaks
from google.protobuf.internal import type_checkers
from google.protobuf.internal import wire_format
from google.protobuf import descriptor
Reported by Pylint.
Line: 58
Column: 1
from google.protobuf import descriptor
try:
import tracemalloc # pylint: disable=g-import-not-at-top
except ImportError:
# Requires python 3.4+
pass
Reported by Pylint.
Line: 189
Column: 3
# implementation because some protect members are called.
# The test is added for historical reasons. It is not necessary as
# serialized string is checked.
# TODO(jieluo): Remove message._unknown_fields.
def InternalCheckUnknownField(self, name, expected_value):
if api_implementation.Type() == 'cpp':
return
field_descriptor = self.descriptor.fields_by_name[name]
wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type]
Reported by Pylint.
Line: 197
Column: 29
wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type]
field_tag = encoder.TagBytes(field_descriptor.number, wire_type)
result_dict = {}
for tag_bytes, value in self.empty_message._unknown_fields:
if tag_bytes == field_tag:
decoder = unittest_pb2.TestAllTypes._decoders_by_tag[tag_bytes][0]
decoder(memoryview(value), 0, len(value), self.all_fields, result_dict)
self.assertEqual(expected_value, result_dict[field_descriptor])
Reported by Pylint.
Line: 199
Column: 19
result_dict = {}
for tag_bytes, value in self.empty_message._unknown_fields:
if tag_bytes == field_tag:
decoder = unittest_pb2.TestAllTypes._decoders_by_tag[tag_bytes][0]
decoder(memoryview(value), 0, len(value), self.all_fields, result_dict)
self.assertEqual(expected_value, result_dict[field_descriptor])
def CheckUnknownField(self, name, unknown_fields, expected_value):
field_descriptor = self.descriptor.fields_by_name[name]
Reported by Pylint.
java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
295 issues
Line: 875
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
/** Like {@link #internalGetMapField} but return a mutable version. */
@SuppressWarnings({"unused", "rawtypes"})
Reported by PMD.
Line: 884
protected MapField internalGetMutableMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
}
// =================================================================
Reported by PMD.
Line: 1846
try {
return clazz.getMethod(name, params);
} catch (NoSuchMethodException e) {
throw new RuntimeException(
"Generated message class \"" + clazz.getName() +
"\" missing method \"" + name + "\".", e);
}
}
Reported by PMD.
Line: 1858
try {
return method.invoke(object, params);
} catch (IllegalAccessException e) {
throw new RuntimeException(
"Couldn't use Java reflection to implement protocol message " +
"reflection.", e);
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
Reported by PMD.
Line: 1868
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
throw new RuntimeException(
"Unexpected exception thrown by generated accessor method.", cause);
}
}
}
Reported by PMD.
Line: 1887
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
/**
* Users should ignore this class. This class provides the implementation
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 static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
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 static com.google.protobuf.Internal.checkNotNull;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
Reported by PMD.
Line: 79
*
* @author kenton@google.com Kenton Varda
*/
public abstract class GeneratedMessageV3 extends AbstractMessage
implements Serializable {
private static final long serialVersionUID = 1L;
/**
* For testing. Allows a test to disable the optimization that avoids using field builders for
Reported by PMD.
Line: 79
*
* @author kenton@google.com Kenton Varda
*/
public abstract class GeneratedMessageV3 extends AbstractMessage
implements Serializable {
private static final long serialVersionUID = 1L;
/**
* For testing. Allows a test to disable the optimization that avoids using field builders for
Reported by PMD.
java/core/src/test/java/com/google/protobuf/ByteStringTest.java
289 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.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import com.google.protobuf.ByteString.Output;
Reported by PMD.
Line: 61
* tests.
*/
@RunWith(JUnit4.class)
public class ByteStringTest {
private static final Charset UTF_16 = Charset.forName("UTF-16");
static byte[] getTestBytes(int size, long seed) {
Random random = new Random(seed);
Reported by PMD.
Line: 61
* tests.
*/
@RunWith(JUnit4.class)
public class ByteStringTest {
private static final Charset UTF_16 = Charset.forName("UTF-16");
static byte[] getTestBytes(int size, long seed) {
Random random = new Random(seed);
Reported by PMD.
Line: 61
* tests.
*/
@RunWith(JUnit4.class)
public class ByteStringTest {
private static final Charset UTF_16 = Charset.forName("UTF-16");
static byte[] getTestBytes(int size, long seed) {
Random random = new Random(seed);
Reported by PMD.
Line: 91
// Returns true only if the given two arrays have identical contents.
private boolean isArray(byte[] left, byte[] right) {
return left.length == right.length && isArrayRange(left, right, 0, left.length);
}
@Test
public void testCompare_equalByteStrings_compareEqual() throws Exception {
byte[] referenceBytes = getTestBytes();
Reported by PMD.
Line: 100
ByteString string1 = ByteString.copyFrom(referenceBytes);
ByteString string2 = ByteString.copyFrom(referenceBytes);
assertWithMessage("ByteString instances containing the same data must compare equal.")
.that(ByteString.unsignedLexicographicalComparator().compare(string1, string2))
.isEqualTo(0);
}
@Test
Reported by PMD.
Line: 100
ByteString string1 = ByteString.copyFrom(referenceBytes);
ByteString string2 = ByteString.copyFrom(referenceBytes);
assertWithMessage("ByteString instances containing the same data must compare equal.")
.that(ByteString.unsignedLexicographicalComparator().compare(string1, string2))
.isEqualTo(0);
}
@Test
Reported by PMD.
Line: 101
ByteString string2 = ByteString.copyFrom(referenceBytes);
assertWithMessage("ByteString instances containing the same data must compare equal.")
.that(ByteString.unsignedLexicographicalComparator().compare(string1, string2))
.isEqualTo(0);
}
@Test
public void testCompare_byteStringsSortLexicographically() throws Exception {
Reported by PMD.
Line: 106
}
@Test
public void testCompare_byteStringsSortLexicographically() throws Exception {
ByteString app = ByteString.copyFromUtf8("app");
ByteString apple = ByteString.copyFromUtf8("apple");
ByteString banana = ByteString.copyFromUtf8("banana");
Comparator<ByteString> comparator = ByteString.unsignedLexicographicalComparator();
Reported by PMD.
Line: 113
Comparator<ByteString> comparator = ByteString.unsignedLexicographicalComparator();
assertWithMessage("ByteString(app) < ByteString(apple)")
.that(comparator.compare(app, apple) < 0)
.isTrue();
assertWithMessage("ByteString(app) < ByteString(banana)")
.that(comparator.compare(app, banana) < 0)
.isTrue();
Reported by PMD.
java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
283 issues
Line: 601
}
if (types.containsKey(message.getFullName())) {
logger.warning("Type " + message.getFullName() + " is added multiple times.");
return;
}
types.put(message.getFullName(), message);
}
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.util;
import com.google.common.base.Preconditions;
import com.google.common.io.BaseEncoding;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.Gson;
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.util;
import com.google.common.base.Preconditions;
import com.google.common.io.BaseEncoding;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.gson.Gson;
Reported by PMD.
Line: 101
* do not exist. This applies to proto2 messages embedded in proto3 messages
* as well.
*/
public class JsonFormat {
private static final Logger logger = Logger.getLogger(JsonFormat.class.getName());
private JsonFormat() {}
/**
Reported by PMD.
Line: 111
*/
public static Printer printer() {
return new Printer(
com.google.protobuf.TypeRegistry.getEmptyTypeRegistry(),
TypeRegistry.getEmptyTypeRegistry(),
/* alwaysOutputDefaultValueFields */ false,
/* includingDefaultValueFields */ Collections.<FieldDescriptor>emptySet(),
/* preservingProtoFieldNames */ false,
/* omittingInsignificantWhitespace */ false,
Reported by PMD.
Line: 124
/**
* A Printer converts protobuf message to JSON format.
*/
public static class Printer {
private final com.google.protobuf.TypeRegistry registry;
private final TypeRegistry oldRegistry;
// NOTE: There are 3 states for these *defaultValueFields variables:
// 1) Default - alwaysOutput is false & including is empty set. Fields only output if they are
// set to non-default values.
Reported by PMD.
Line: 125
* A Printer converts protobuf message to JSON format.
*/
public static class Printer {
private final com.google.protobuf.TypeRegistry registry;
private final TypeRegistry oldRegistry;
// NOTE: There are 3 states for these *defaultValueFields variables:
// 1) Default - alwaysOutput is false & including is empty set. Fields only output if they are
// set to non-default values.
// 2) No-args includingDefaultValueFields() called - alwaysOutput is true & including is
Reported by PMD.
Line: 126
*/
public static class Printer {
private final com.google.protobuf.TypeRegistry registry;
private final TypeRegistry oldRegistry;
// NOTE: There are 3 states for these *defaultValueFields variables:
// 1) Default - alwaysOutput is false & including is empty set. Fields only output if they are
// set to non-default values.
// 2) No-args includingDefaultValueFields() called - alwaysOutput is true & including is
// irrelevant (but set to empty set). All fields are output regardless of their values.
Reported by PMD.
Line: 135
// 3) includingDefaultValueFields(Set<FieldDescriptor>) called - alwaysOutput is false &
// including is set to the specified set. Fields in that set are always output & fields not
// in that set are only output if set to non-default values.
private boolean alwaysOutputDefaultValueFields;
private Set<FieldDescriptor> includingDefaultValueFields;
private final boolean preservingProtoFieldNames;
private final boolean omittingInsignificantWhitespace;
private final boolean printingEnumsAsInts;
private final boolean sortingMapKeys;
Reported by PMD.
Line: 135
// 3) includingDefaultValueFields(Set<FieldDescriptor>) called - alwaysOutput is false &
// including is set to the specified set. Fields in that set are always output & fields not
// in that set are only output if set to non-default values.
private boolean alwaysOutputDefaultValueFields;
private Set<FieldDescriptor> includingDefaultValueFields;
private final boolean preservingProtoFieldNames;
private final boolean omittingInsignificantWhitespace;
private final boolean printingEnumsAsInts;
private final boolean sortingMapKeys;
Reported by PMD.
java/core/src/main/java/com/google/protobuf/GeneratedMessage.java
281 issues
Line: 720
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
/** Like {@link #internalGetMapField} but return a mutable version. */
@SuppressWarnings({"unused", "rawtypes"})
Reported by PMD.
Line: 729
protected MapField internalGetMutableMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
}
// =================================================================
Reported by PMD.
Line: 1719
FileDescriptor file = (FileDescriptor) clazz.getField("descriptor").get(null);
return file.findExtensionByName(extensionName);
} catch (Exception e) {
throw new RuntimeException(
"Cannot load descriptors: "
+ descriptorOuterClass
+ " is not a valid descriptor class name",
e);
}
Reported by PMD.
Line: 1972
try {
return clazz.getMethod(name, params);
} catch (NoSuchMethodException e) {
throw new RuntimeException(
"Generated message class \"" + clazz.getName() +
"\" missing method \"" + name + "\".", e);
}
}
Reported by PMD.
Line: 1984
try {
return method.invoke(object, params);
} catch (IllegalAccessException e) {
throw new RuntimeException(
"Couldn't use Java reflection to implement protocol message " +
"reflection.", e);
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
Reported by PMD.
Line: 1994
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
throw new RuntimeException(
"Unexpected exception thrown by generated accessor method.", cause);
}
}
}
Reported by PMD.
Line: 2015
protected MapField internalGetMapField(int fieldNumber) {
// Note that we can't use descriptor names here because this method will
// be called when descriptor is being initialized.
throw new RuntimeException(
"No map fields found in " + getClass().getName());
}
/**
* Users should ignore this class. This class provides the implementation
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 com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
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 com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
Reported by PMD.
Line: 61
*
* @author kenton@google.com Kenton Varda
*/
public abstract class GeneratedMessage extends AbstractMessage
implements Serializable {
private static final long serialVersionUID = 1L;
/**
* For testing. Allows a test to disable the optimization that avoids using
Reported by PMD.
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
270 issues
Line: 98
RubyHash hash = args[0].convertToHash();
hash.visitAll(new RubyHash.Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (!(key instanceof RubySymbol) && !(key instanceof RubyString))
throw runtime.newTypeError("Expected string or symbols as hash keys in initialization map.");
final FieldDescriptor fieldDescriptor = findField(context, key, ignoreUnknownFieldsOnInit);
if (value == null || value.isNil()) return;
Reported by PMD.
Line: 938
return context.nil;
}
private IRubyObject setFieldInternal(ThreadContext context, FieldDescriptor fieldDescriptor, IRubyObject value) {
testFrozen("can't modify frozen " + getMetaClass());
if (Utils.isMapEntry(fieldDescriptor)) {
if (!(value instanceof RubyMap)) {
throw Utils.createTypeError(context, "Expected Map instance");
Reported by PMD.
Line: 938
return context.nil;
}
private IRubyObject setFieldInternal(ThreadContext context, FieldDescriptor fieldDescriptor, IRubyObject value) {
testFrozen("can't modify frozen " + getMetaClass());
if (Utils.isMapEntry(fieldDescriptor)) {
if (!(value instanceof RubyMap)) {
throw Utils.createTypeError(context, "Expected Map instance");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 63
import java.util.List;
import java.util.Map;
public class RubyMessage extends RubyObject {
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) {
super(runtime, klazz);
this.descriptor = descriptor;
this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
Reported by PMD.
Line: 89
* Message class are provided on each concrete message class.
*/
@JRubyMethod(optional = 1)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
if (args.length == 1) {
if (!(args[0] instanceof RubyHash)) {
throw runtime.newArgumentError("expected Hash arguments.");
}
Reported by PMD.