The following issues were found
java/core/src/main/java/com/google/protobuf/BinaryReader.java
197 issues
Line: 1489
case UINT64:
return readUInt64();
default:
throw new RuntimeException("unsupported field type.");
}
}
/** Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits. */
private int readVarint32() throws IOException {
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.WireFormat.FIXED32_SIZE;
import static com.google.protobuf.WireFormat.FIXED64_SIZE;
import static com.google.protobuf.WireFormat.WIRETYPE_END_GROUP;
import static com.google.protobuf.WireFormat.WIRETYPE_FIXED32;
Reported by PMD.
Line: 52
* protocol.
*/
@ExperimentalApi
abstract class BinaryReader implements Reader {
private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
/**
* Creates a new reader using the given {@code buffer} as input.
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 91
* A {@link BinaryReader} implementation that operates on a heap {@link ByteBuffer}. Uses only
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
Reported by PMD.
Line: 92
* safe operations on the underlying array.
*/
private static final class SafeHeapReader extends BinaryReader {
private final boolean bufferIsImmutable;
private final byte[] buffer;
private int pos;
private final int initialPos;
private int limit;
private int tag;
Reported by PMD.
python/setup.py
195 issues
Line: 184
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b602_subprocess_popen_with_shell_equals_true.html
os.environ["CONFORMANCE_PYTHON_EXTRA_FAILURES"] = (
"--failure_list failure_list_python-post26.txt")
cmd = 'cd ../conformance && make %s' % (test_conformance.target)
status = subprocess.check_call(cmd, shell=True)
def get_option_from_sys_argv(option_str):
if option_str in sys.argv:
sys.argv.remove(option_str)
Reported by Bandit.
Line: 48
Column: 12
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals())
global __version__
return __version__
def generate_proto(source, require = True):
"""Invokes the Protocol Compiler to generate a _pb2.py from the given
.proto file. Does nothing if the output already exists and is newer than
Reported by Pylint.
Line: 13
Column: 1
import subprocess
import sys
import sysconfig
import platform
# We must use setuptools, not distutils, because we need to use the
# namespace_packages option for the "google" package.
from setuptools import setup, Extension, find_packages
Reported by Pylint.
Line: 46
Column: 5
protobuf library may be loaded instead."""
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals())
global __version__
return __version__
def generate_proto(source, require = True):
Reported by Pylint.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
protobuf library may be loaded instead."""
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals())
global __version__
return __version__
def generate_proto(source, require = True):
Reported by Bandit.
Line: 47
Column: 5
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
exec(version_file.read(), globals())
global __version__
return __version__
def generate_proto(source, require = True):
"""Invokes the Protocol Compiler to generate a _pb2.py from the given
Reported by Pylint.
Line: 120
Column: 19
class clean(_clean):
def run(self):
# Delete generated files in the code tree.
for (dirpath, dirnames, filenames) in os.walk("."):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
filepath.endswith(".so") or filepath.endswith(".o"):
os.remove(filepath)
Reported by Pylint.
Line: 184
Column: 5
os.environ["CONFORMANCE_PYTHON_EXTRA_FAILURES"] = (
"--failure_list failure_list_python-post26.txt")
cmd = 'cd ../conformance && make %s' % (test_conformance.target)
status = subprocess.check_call(cmd, shell=True)
def get_option_from_sys_argv(option_str):
if option_str in sys.argv:
sys.argv.remove(option_str)
Reported by Pylint.
Line: 220
Column: 1
extra_compile_args.append('-std=c++11')
if sys.platform == 'darwin':
extra_compile_args.append("-Wno-shorten-64-to-32");
extra_compile_args.append("-Wno-deprecated-register");
# https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
# C++ projects must now migrate to libc++ and are recommended to set a
# deployment target of macOS 10.9 or later, or iOS 7 or later.
Reported by Pylint.
Line: 221
Column: 1
if sys.platform == 'darwin':
extra_compile_args.append("-Wno-shorten-64-to-32");
extra_compile_args.append("-Wno-deprecated-register");
# https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
# C++ projects must now migrate to libc++ and are recommended to set a
# deployment target of macOS 10.9 or later, or iOS 7 or later.
if sys.platform == 'darwin':
Reported by Pylint.
java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java
189 issues
Line: 53
/** Tests related to unknown field handling. */
@RunWith(JUnit4.class)
public class UnknownFieldSetTest {
@Before
public void setUp() throws Exception {
descriptor = TestAllTypes.getDescriptor();
allFields = TestUtil.getAllSet();
Reported by PMD.
Line: 66
UnknownFieldSet.Field getField(String name) {
Descriptors.FieldDescriptor field = descriptor.findFieldByName(name);
assertThat(field).isNotNull();
return unknownFields.getField(field.getNumber());
}
// Constructs a protocol buffer which contains fields with all the same
// numbers as allFieldsData except that each field is some other wire
Reported by PMD.
Line: 67
UnknownFieldSet.Field getField(String name) {
Descriptors.FieldDescriptor field = descriptor.findFieldByName(name);
assertThat(field).isNotNull();
return unknownFields.getField(field.getNumber());
}
// Constructs a protocol buffer which contains fields with all the same
// numbers as allFieldsData except that each field is some other wire
// type.
Reported by PMD.
Line: 73
// Constructs a protocol buffer which contains fields with all the same
// numbers as allFieldsData except that each field is some other wire
// type.
ByteString getBizarroData() throws Exception {
UnknownFieldSet.Builder bizarroFields = UnknownFieldSet.newBuilder();
UnknownFieldSet.Field varintField = UnknownFieldSet.Field.newBuilder().addVarint(1).build();
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
Reported by PMD.
Line: 76
ByteString getBizarroData() throws Exception {
UnknownFieldSet.Builder bizarroFields = UnknownFieldSet.newBuilder();
UnknownFieldSet.Field varintField = UnknownFieldSet.Field.newBuilder().addVarint(1).build();
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
if (entry.getValue().getVarintList().isEmpty()) {
// Original field is not a varint, so use a varint.
Reported by PMD.
Line: 77
UnknownFieldSet.Builder bizarroFields = UnknownFieldSet.newBuilder();
UnknownFieldSet.Field varintField = UnknownFieldSet.Field.newBuilder().addVarint(1).build();
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
if (entry.getValue().getVarintList().isEmpty()) {
// Original field is not a varint, so use a varint.
bizarroFields.addField(entry.getKey(), varintField);
Reported by PMD.
Line: 79
UnknownFieldSet.Field varintField = UnknownFieldSet.Field.newBuilder().addVarint(1).build();
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
if (entry.getValue().getVarintList().isEmpty()) {
// Original field is not a varint, so use a varint.
bizarroFields.addField(entry.getKey(), varintField);
} else {
// Original field *is* a varint, so use something else.
Reported by PMD.
Line: 80
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
if (entry.getValue().getVarintList().isEmpty()) {
// Original field is not a varint, so use a varint.
bizarroFields.addField(entry.getKey(), varintField);
} else {
// Original field *is* a varint, so use something else.
bizarroFields.addField(entry.getKey(), fixed32Field);
Reported by PMD.
Line: 80
UnknownFieldSet.Field fixed32Field = UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
if (entry.getValue().getVarintList().isEmpty()) {
// Original field is not a varint, so use a varint.
bizarroFields.addField(entry.getKey(), varintField);
} else {
// Original field *is* a varint, so use something else.
bizarroFields.addField(entry.getKey(), fixed32Field);
Reported by PMD.
Line: 89
}
}
return bizarroFields.build().toByteString();
}
Descriptors.Descriptor descriptor;
TestAllTypes allFields;
ByteString allFieldsData;
Reported by PMD.
java/core/src/main/java/com/google/protobuf/Descriptors.java
189 issues
Line: 1337
static {
// Refuse to init if someone added a new declared type.
if (Type.types.length != FieldDescriptorProto.Type.values().length) {
throw new RuntimeException(
"descriptor.proto has a new declared type but Descriptors.java wasn't updated.");
}
}
public enum JavaType {
Reported by PMD.
Line: 182
* @param name The unqualified type name to look for.
* @return The message type's descriptor, or {@code null} if not found.
*/
public Descriptor findMessageTypeByName(String name) {
// Don't allow looking up nested types. This will make optimization
// easier later.
if (name.indexOf('.') != -1) {
return null;
}
Reported by PMD.
Line: 206
* @param name The unqualified type name to look for.
* @return The enum type's descriptor, or {@code null} if not found.
*/
public EnumDescriptor findEnumTypeByName(String name) {
// Don't allow looking up nested types. This will make optimization
// easier later.
if (name.indexOf('.') != -1) {
return null;
}
Reported by PMD.
Line: 230
* @param name The unqualified type name to look for.
* @return The service type's descriptor, or {@code null} if not found.
*/
public ServiceDescriptor findServiceByName(String name) {
// Don't allow looking up nested types. This will make optimization
// easier later.
if (name.indexOf('.') != -1) {
return null;
}
Reported by PMD.
Line: 254
* @param name The unqualified extension name to look for.
* @return The extension's descriptor, or {@code null} if not found.
*/
public FieldDescriptor findExtensionByName(String name) {
if (name.indexOf('.') != -1) {
return null;
}
final String packageName = getPackage();
if (!packageName.isEmpty()) {
Reported by PMD.
Line: 349
} catch (Exception e) {
// We allow unknown dependencies by default. If a dependency cannot
// be found we only generate a warning.
logger.warning("Descriptors for \"" + dependencyFileNames[i] + "\" can not be found.");
}
}
return descriptors.toArray(new FileDescriptor[0]);
}
Reported by PMD.
Line: 1786
// Note: We must use "new Integer(number)" here because we don't want
// these Integer objects to be cached.
Integer key = new Integer(number);
WeakReference<EnumValueDescriptor> reference = unknownValues.get(key);
if (reference != null) {
result = reference.get();
}
if (result == null) {
Reported by PMD.
Line: 2452
if (result == null) {
if (allowUnknownDependencies && filter == SearchFilter.TYPES_ONLY) {
logger.warning(
"The descriptor for message type \""
+ name
+ "\" can not be found and a placeholder is created for it");
// We create a dummy message descriptor here regardless of the
// expected type. If the type should be message, this dummy
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.DescriptorProtos.DescriptorProto;
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
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.DescriptorProtos.DescriptorProto;
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
Reported by PMD.
java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
184 issues
Line: 639
Method getter = messageType.getDeclaredMethod(getterForField(name));
return getter.getReturnType();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** Inspects the message to identify the message type of a repeated message field. */
private static Class<?> getTypeForRepeatedMessageField(Class<?> messageType, FieldDescriptor fd) {
Reported by PMD.
Line: 650
Method getter = messageType.getDeclaredMethod(getterForField(name), int.class);
return getter.getReturnType();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/** Constructs the name of the get method for the given field in the proto. */
private static String getterForField(String snakeCase) {
Reported by PMD.
Line: 61
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */
@ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
Reported by PMD.
Line: 61
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */
@ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
Reported by PMD.
Line: 61
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */
@ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
Reported by PMD.
Line: 61
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */
@ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
Reported by PMD.
Line: 61
/** A factory for message info based on protobuf descriptors for a {@link GeneratedMessageV3}. */
@ExperimentalApi
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
Reported by PMD.
Line: 91
private static Message getDefaultInstance(Class<?> messageType) {
try {
Method method = messageType.getDeclaredMethod(GET_DEFAULT_INSTANCE_METHOD_NAME);
return (Message) method.invoke(null);
} catch (Exception e) {
throw new IllegalArgumentException(
"Unable to get default instance for message class " + messageType.getName(), e);
}
}
Reported by PMD.
Line: 92
try {
Method method = messageType.getDeclaredMethod(GET_DEFAULT_INSTANCE_METHOD_NAME);
return (Message) method.invoke(null);
} catch (Exception e) {
throw new IllegalArgumentException(
"Unable to get default instance for message class " + messageType.getName(), e);
}
}
Reported by PMD.
Line: 99
}
private static Descriptor descriptorForType(Class<?> messageType) {
return getDefaultInstance(messageType).getDescriptorForType();
}
private static MessageInfo convert(Class<?> messageType, Descriptor messageDescriptor) {
switch (messageDescriptor.getFile().getSyntax()) {
case PROTO2:
Reported by PMD.
update_version.py
180 issues
Line: 65
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-minidom
def RewriteXml(filename, rewriter, add_xml_prefix=True):
document = minidom.parse(filename)
rewriter(document)
# document.toxml() always prepend the XML version without inserting new line.
# We wants to preserve as much of the original formatting as possible, so we
# will remove the default XML version and replace it with our custom one when
# whever necessary.
Reported by Bandit.
Line: 1
Column: 1
#!/usr/bin/env python
# Usage: ./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
#
# Example:
# ./update_version.py 3.7.1 2
# => Version will become 3.7.1-rc-2 (beta)
# ./update_version.py 3.7.1
# => Version will become 3.7.1 (stable)
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b408-import-xml-minidom
import datetime
import re
import sys
from xml.dom import minidom
if len(sys.argv) < 2 or len(sys.argv) > 3:
print("""
[ERROR] Please specify a version.
Reported by Bandit.
Line: 16
Column: 1
from xml.dom import minidom
if len(sys.argv) < 2 or len(sys.argv) > 3:
print("""
[ERROR] Please specify a version.
./update_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
Example:
Reported by Pylint.
Line: 24
Column: 1
Example:
./update_version.py 3.7.1 2
""")
exit(1)
NEW_VERSION = sys.argv[1]
NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
if len(NEW_VERSION_INFO) != 3:
print("""
Reported by Pylint.
Line: 24
Column: 3
Example:
./update_version.py 3.7.1 2
""")
exit(1)
NEW_VERSION = sys.argv[1]
NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
if len(NEW_VERSION_INFO) != 3:
print("""
Reported by Pylint.
Line: 29
Column: 1
NEW_VERSION = sys.argv[1]
NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')]
if len(NEW_VERSION_INFO) != 3:
print("""
[ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
Example:
./update_version.py 3.7.3
""")
Reported by Pylint.
Line: 35
Column: 1
Example:
./update_version.py 3.7.3
""")
exit(1)
RC_VERSION = -1
if len(sys.argv) > 2:
RC_VERSION = int(sys.argv[2])
Reported by Pylint.
Line: 35
Column: 3
Example:
./update_version.py 3.7.3
""")
exit(1)
RC_VERSION = -1
if len(sys.argv) > 2:
RC_VERSION = int(sys.argv[2])
Reported by Pylint.
Line: 39
Column: 1
RC_VERSION = -1
if len(sys.argv) > 2:
RC_VERSION = int(sys.argv[2])
def Find(elem, tagname):
for child in elem.childNodes:
if child.nodeName == tagname:
Reported by Pylint.
java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
178 issues
Line: 447
} catch (IndexOutOfBoundsException e) {
throw InvalidProtocolBufferException.truncatedMessage();
} catch (IOException e) {
throw new RuntimeException("Reading from byte array should not throw IOException.", e);
}
return (BuilderType) this;
}
@Override
Reported by PMD.
Line: 1155
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: 1166
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) {
throw (RuntimeException) cause;
Reported by PMD.
Line: 1175
} else if (cause instanceof Error) {
throw (Error) cause;
} else {
throw new RuntimeException(
"Unexpected exception thrown by generated accessor method.", cause);
}
}
}
Reported by PMD.
Line: 1355
MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null);
return defaultInstance.newBuilderForType().mergeFrom(asBytes).buildPartial();
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
return readResolveFallback();
} catch (SecurityException e) {
throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
} catch (IllegalAccessException e) {
Reported by PMD.
Line: 1359
} catch (NoSuchFieldException e) {
return readResolveFallback();
} catch (SecurityException e) {
throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to call parsePartialFrom", e);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Unable to understand proto buffer", e);
}
Reported by PMD.
Line: 1361
} catch (SecurityException e) {
throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to call parsePartialFrom", e);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Unable to understand proto buffer", e);
}
}
Reported by PMD.
Line: 1363
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to call parsePartialFrom", e);
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Unable to understand proto buffer", e);
}
}
/**
* @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
Reported by PMD.
Line: 1382
.mergeFrom(asBytes)
.buildPartial();
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e);
} catch (SecurityException e) {
throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e);
} catch (IllegalAccessException e) {
Reported by PMD.
Line: 1384
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e);
} catch (SecurityException e) {
throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Unable to call parsePartialFrom", e);
} catch (InvalidProtocolBufferException e) {
Reported by PMD.
java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java
178 issues
Line: 57
public class UnknownEnumValueTest {
@Test
public void testUnknownEnumValues() throws Exception {
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
builder.setOptionalNestedEnumValue(4321);
builder.addRepeatedNestedEnumValue(5432);
builder.addPackedNestedEnumValue(6543);
TestAllTypes message = builder.build();
Reported by PMD.
Line: 63
builder.addRepeatedNestedEnumValue(5432);
builder.addPackedNestedEnumValue(6543);
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
Reported by PMD.
Line: 63
builder.addRepeatedNestedEnumValue(5432);
builder.addPackedNestedEnumValue(6543);
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
Reported by PMD.
Line: 64
builder.addPackedNestedEnumValue(6543);
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
Reported by PMD.
Line: 64
builder.addPackedNestedEnumValue(6543);
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
Reported by PMD.
Line: 65
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnumList().get(0))
Reported by PMD.
Line: 65
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnumList().get(0))
Reported by PMD.
Line: 65
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnumList().get(0))
Reported by PMD.
Line: 65
TestAllTypes message = builder.build();
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnumList().get(0))
Reported by PMD.
Line: 66
assertThat(message.getOptionalNestedEnumValue()).isEqualTo(4321);
assertThat(message.getRepeatedNestedEnumValue(0)).isEqualTo(5432);
assertThat(message.getRepeatedNestedEnumValueList().get(0).intValue()).isEqualTo(5432);
assertThat(message.getPackedNestedEnumValue(0)).isEqualTo(6543);
// Returns UNRECOGNIZED if an enum type is requested.
assertThat(message.getOptionalNestedEnum()).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnum(0)).isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
assertThat(message.getRepeatedNestedEnumList().get(0))
.isEqualTo(TestAllTypes.NestedEnum.UNRECOGNIZED);
Reported by PMD.
java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
173 issues
Line: 427
private void assertImmutable(FloatList list) {
if (list.contains(1F)) {
throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
}
try {
list.add(1F);
assertWithMessage("expected exception").fail();
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link FloatArrayList}. */
@RunWith(JUnit4.class)
public class FloatArrayListTest {
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
Reported by PMD.
Line: 53
private static final FloatArrayList UNARY_LIST = newImmutableFloatArrayList(1);
private static final FloatArrayList TERTIARY_LIST = newImmutableFloatArrayList(1, 2, 3);
private FloatArrayList list;
@Before
public void setUp() throws Exception {
list = new FloatArrayList();
}
Reported by PMD.
Line: 62
@Test
public void testEmptyListReturnsSameInstance() {
assertThat(FloatArrayList.emptyList()).isSameInstanceAs(FloatArrayList.emptyList());
}
@Test
public void testEmptyListIsImmutable() {
assertImmutable(FloatArrayList.emptyList());
Reported by PMD.
Line: 81
}
@Test
public void testModificationWithIteration() {
list.addAll(asList(1F, 2F, 3F, 4F));
Iterator<Float> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((float) list.get(0)).isEqualTo(1F);
assertThat((float) iterator.next()).isEqualTo(1F);
Reported by PMD.
Line: 84
public void testModificationWithIteration() {
list.addAll(asList(1F, 2F, 3F, 4F));
Iterator<Float> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((float) list.get(0)).isEqualTo(1F);
assertThat((float) iterator.next()).isEqualTo(1F);
list.set(0, 1F);
assertThat((float) iterator.next()).isEqualTo(2F);
Reported by PMD.
Line: 93
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.
java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
173 issues
Line: 427
private void assertImmutable(DoubleList list) {
if (list.contains(1D)) {
throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
}
try {
list.add(1D);
assertWithMessage("expected exception").fail();
Reported by PMD.
Line: 48
/** Tests for {@link DoubleArrayList}. */
@RunWith(JUnit4.class)
public class DoubleArrayListTest {
private static final DoubleArrayList UNARY_LIST = newImmutableDoubleArrayList(1);
private static final DoubleArrayList TERTIARY_LIST = newImmutableDoubleArrayList(1, 2, 3);
private DoubleArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link DoubleArrayList}. */
@RunWith(JUnit4.class)
public class DoubleArrayListTest {
private static final DoubleArrayList UNARY_LIST = newImmutableDoubleArrayList(1);
private static final DoubleArrayList TERTIARY_LIST = newImmutableDoubleArrayList(1, 2, 3);
private DoubleArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link DoubleArrayList}. */
@RunWith(JUnit4.class)
public class DoubleArrayListTest {
private static final DoubleArrayList UNARY_LIST = newImmutableDoubleArrayList(1);
private static final DoubleArrayList TERTIARY_LIST = newImmutableDoubleArrayList(1, 2, 3);
private DoubleArrayList list;
Reported by PMD.
Line: 48
/** Tests for {@link DoubleArrayList}. */
@RunWith(JUnit4.class)
public class DoubleArrayListTest {
private static final DoubleArrayList UNARY_LIST = newImmutableDoubleArrayList(1);
private static final DoubleArrayList TERTIARY_LIST = newImmutableDoubleArrayList(1, 2, 3);
private DoubleArrayList list;
Reported by PMD.
Line: 53
private static final DoubleArrayList UNARY_LIST = newImmutableDoubleArrayList(1);
private static final DoubleArrayList TERTIARY_LIST = newImmutableDoubleArrayList(1, 2, 3);
private DoubleArrayList list;
@Before
public void setUp() throws Exception {
list = new DoubleArrayList();
}
Reported by PMD.
Line: 62
@Test
public void testEmptyListReturnsSameInstance() {
assertThat(DoubleArrayList.emptyList()).isSameInstanceAs(DoubleArrayList.emptyList());
}
@Test
public void testEmptyListIsImmutable() {
assertImmutable(DoubleArrayList.emptyList());
Reported by PMD.
Line: 81
}
@Test
public void testModificationWithIteration() {
list.addAll(asList(1D, 2D, 3D, 4D));
Iterator<Double> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((double) list.get(0)).isEqualTo(1D);
assertThat((double) iterator.next()).isEqualTo(1D);
Reported by PMD.
Line: 84
public void testModificationWithIteration() {
list.addAll(asList(1D, 2D, 3D, 4D));
Iterator<Double> iterator = list.iterator();
assertThat(list).hasSize(4);
assertThat((double) list.get(0)).isEqualTo(1D);
assertThat((double) iterator.next()).isEqualTo(1D);
list.set(0, 1D);
assertThat((double) iterator.next()).isEqualTo(2D);
Reported by PMD.
Line: 93
list.remove(0);
try {
iterator.next();
assertWithMessage("expected exception").fail();
} catch (ConcurrentModificationException e) {
// expected
}
iterator = list.iterator();
Reported by PMD.