The following issues were found

java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java
136 issues
Avoid throwing raw exception types.
Design

Line: 247

              
  private void assertImmutable(List<Integer> list) {
    if (list.contains(1)) {
      throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
    }

    try {
      list.add(1);
      fail();

            

Reported by PMD.

The class 'ProtobufArrayListTest' has a Modified Cyclomatic Complexity of 4 (Highest = 21).
Design

Line: 42

              import junit.framework.TestCase;

/** Tests for {@link ProtobufArrayList}. */
public class ProtobufArrayListTest extends TestCase {

  private static final ProtobufArrayList<Integer> UNARY_LIST = newImmutableProtoArrayList(1);
  private static final ProtobufArrayList<Integer> TERTIARY_LIST =
      newImmutableProtoArrayList(1, 2, 3);


            

Reported by PMD.

The class 'ProtobufArrayListTest' has a Standard Cyclomatic Complexity of 4 (Highest = 21).
Design

Line: 42

              import junit.framework.TestCase;

/** Tests for {@link ProtobufArrayList}. */
public class ProtobufArrayListTest extends TestCase {

  private static final ProtobufArrayList<Integer> UNARY_LIST = newImmutableProtoArrayList(1);
  private static final ProtobufArrayList<Integer> TERTIARY_LIST =
      newImmutableProtoArrayList(1, 2, 3);


            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 42

              import junit.framework.TestCase;

/** Tests for {@link ProtobufArrayList}. */
public class ProtobufArrayListTest extends TestCase {

  private static final ProtobufArrayList<Integer> UNARY_LIST = newImmutableProtoArrayList(1);
  private static final ProtobufArrayList<Integer> TERTIARY_LIST =
      newImmutableProtoArrayList(1, 2, 3);


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 48

                private static final ProtobufArrayList<Integer> TERTIARY_LIST =
      newImmutableProtoArrayList(1, 2, 3);

  private ProtobufArrayList<Integer> list;

  @Override
  protected void setUp() throws Exception {
    list = new ProtobufArrayList<Integer>();
  }

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 50

              
  private ProtobufArrayList<Integer> list;

  @Override
  protected void setUp() throws Exception {
    list = new ProtobufArrayList<Integer>();
  }

  public void testEmptyListReturnsSameInstance() {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 55

                  list = new ProtobufArrayList<Integer>();
  }

  public void testEmptyListReturnsSameInstance() {
    assertSame(ProtobufArrayList.emptyList(), ProtobufArrayList.emptyList());
  }

  public void testEmptyListIsImmutable() {
    assertImmutable(ProtobufArrayList.<Integer>emptyList());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 56

                }

  public void testEmptyListReturnsSameInstance() {
    assertSame(ProtobufArrayList.emptyList(), ProtobufArrayList.emptyList());
  }

  public void testEmptyListIsImmutable() {
    assertImmutable(ProtobufArrayList.<Integer>emptyList());
  }

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 59

                  assertSame(ProtobufArrayList.emptyList(), ProtobufArrayList.emptyList());
  }

  public void testEmptyListIsImmutable() {
    assertImmutable(ProtobufArrayList.<Integer>emptyList());
  }

  public void testModificationWithIteration() {
    list.addAll(asList(1, 2, 3, 4));

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 63

                  assertImmutable(ProtobufArrayList.<Integer>emptyList());
  }

  public void testModificationWithIteration() {
    list.addAll(asList(1, 2, 3, 4));
    Iterator<Integer> iterator = list.iterator();
    assertEquals(4, list.size());
    assertEquals(1, (int) list.get(0));
    assertEquals(1, (int) iterator.next());

            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java
129 issues
The class 'LazyStringArrayListTest' has a Modified Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 48

              
/** Tests for {@link LazyStringArrayList}. */
@RunWith(JUnit4.class)
public class LazyStringArrayListTest {

  private static final String STRING_A = "A";
  private static final String STRING_B = "B";
  private static final String STRING_C = "C";


            

Reported by PMD.

The class 'LazyStringArrayListTest' has a Standard Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 48

              
/** Tests for {@link LazyStringArrayList}. */
@RunWith(JUnit4.class)
public class LazyStringArrayListTest {

  private static final String STRING_A = "A";
  private static final String STRING_B = "B";
  private static final String STRING_C = "C";


            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 59

                private static final ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");

  @Test
  public void testJustStrings() {
    LazyStringArrayList list = new LazyStringArrayList();
    list.add(STRING_A);
    list.add(STRING_B);
    list.add(STRING_C);


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 65

                  list.add(STRING_B);
    list.add(STRING_C);

    assertThat(list).hasSize(3);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_B);
    assertThat(list.get(2)).isSameInstanceAs(STRING_C);

    list.set(1, STRING_C);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 66

                  list.add(STRING_C);

    assertThat(list).hasSize(3);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_B);
    assertThat(list.get(2)).isSameInstanceAs(STRING_C);

    list.set(1, STRING_C);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 67

              
    assertThat(list).hasSize(3);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_B);
    assertThat(list.get(2)).isSameInstanceAs(STRING_C);

    list.set(1, STRING_C);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 68

                  assertThat(list).hasSize(3);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_B);
    assertThat(list.get(2)).isSameInstanceAs(STRING_C);

    list.set(1, STRING_C);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);

    list.remove(1);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 71

                  assertThat(list.get(2)).isSameInstanceAs(STRING_C);

    list.set(1, STRING_C);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);

    list.remove(1);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 74

                  assertThat(list.get(1)).isSameInstanceAs(STRING_C);

    list.remove(1);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);

    List<ByteString> byteStringList = list.asByteStringList();
    assertThat(byteStringList.get(0)).isEqualTo(BYTE_STRING_A);
    assertThat(byteStringList.get(1)).isEqualTo(BYTE_STRING_C);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 75

              
    list.remove(1);
    assertThat(list.get(0)).isSameInstanceAs(STRING_A);
    assertThat(list.get(1)).isSameInstanceAs(STRING_C);

    List<ByteString> byteStringList = list.asByteStringList();
    assertThat(byteStringList.get(0)).isEqualTo(BYTE_STRING_A);
    assertThat(byteStringList.get(1)).isEqualTo(BYTE_STRING_C);


            

Reported by PMD.

python/google/protobuf/internal/_parameterized.py
126 issues
Access to a protected member _id_suffix of a client class
Error

Line: 271 Column: 3

                assert not getattr(class_object, '_id_suffix', None), (
      'Cannot add parameters to %s,'
      ' which already has parameterized methods.' % (class_object,))
  class_object._id_suffix = id_suffix = {}
  # We change the size of __dict__ while we iterate over it,
  # which Python 3.x will complain about, so use copy().
  for name, obj in class_object.__dict__.copy().items():
    if (name.startswith(unittest.TestLoader.testMethodPrefix)
        and isinstance(obj, types.FunctionType)):

            

Reported by Pylint.

Redefining name 'name' from outer scope (line 274)
Error

Line: 282 Column: 7

                    _UpdateClassDictForParamTestCase(
          methods, id_suffix, name,
          _ParameterizedTestIter(obj, testcases, naming_type))
      for name, meth in methods.items():
        setattr(class_object, name, meth)


def _ParameterDecorator(naming_type, testcases):
  """Implementation of the parameterization decorators.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 152 Column: 1

              import re
import types
try:
  import unittest2 as unittest
except ImportError:
  import unittest
import uuid

import six

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 154 Column: 1

              try:
  import unittest2 as unittest
except ImportError:
  import unittest
import uuid

import six

try:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 161 Column: 1

              
try:
  # Since python 3
  import collections.abc as collections_abc
except ImportError:
  # Won't work after python 3.8
  import collections as collections_abc

ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>')

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 164 Column: 1

                import collections.abc as collections_abc
except ImportError:
  # Won't work after python 3.8
  import collections as collections_abc

ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>')
_SEPARATOR = uuid.uuid1().hex
_FIRST_ARG = object()
_ARGUMENT_REPR = object()

            

Reported by Pylint.

Function name "_CleanRepr" doesn't conform to snake_case naming style
Error

Line: 172 Column: 1

              _ARGUMENT_REPR = object()


def _CleanRepr(obj):
  return ADDR_RE.sub(r'<\1>', repr(obj))


# Helper function formerly from the unittest module, removed from it in
# Python 2.7.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 173 Column: 1

              

def _CleanRepr(obj):
  return ADDR_RE.sub(r'<\1>', repr(obj))


# Helper function formerly from the unittest module, removed from it in
# Python 2.7.
def _StrClass(cls):

            

Reported by Pylint.

Function name "_StrClass" doesn't conform to snake_case naming style
Error

Line: 178 Column: 1

              
# Helper function formerly from the unittest module, removed from it in
# Python 2.7.
def _StrClass(cls):
  return '%s.%s' % (cls.__module__, cls.__name__)


def _NonStringIterable(obj):
  return (isinstance(obj, collections_abc.Iterable) and not

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 179 Column: 1

              # Helper function formerly from the unittest module, removed from it in
# Python 2.7.
def _StrClass(cls):
  return '%s.%s' % (cls.__module__, cls.__name__)


def _NonStringIterable(obj):
  return (isinstance(obj, collections_abc.Iterable) and not
          isinstance(obj, six.string_types))

            

Reported by Pylint.

python/google/protobuf/internal/wire_format.py
126 issues
Unused argument 'fixed32'
Error

Line: 151 Column: 35

                return UInt64ByteSize(field_number, ZigZagEncode(int64))


def Fixed32ByteSize(field_number, fixed32):
  return TagByteSize(field_number) + 4


def Fixed64ByteSize(field_number, fixed64):
  return TagByteSize(field_number) + 8

            

Reported by Pylint.

Unused argument 'fixed64'
Error

Line: 155 Column: 35

                return TagByteSize(field_number) + 4


def Fixed64ByteSize(field_number, fixed64):
  return TagByteSize(field_number) + 8


def SFixed32ByteSize(field_number, sfixed32):
  return TagByteSize(field_number) + 4

            

Reported by Pylint.

Unused argument 'sfixed32'
Error

Line: 159 Column: 36

                return TagByteSize(field_number) + 8


def SFixed32ByteSize(field_number, sfixed32):
  return TagByteSize(field_number) + 4


def SFixed64ByteSize(field_number, sfixed64):
  return TagByteSize(field_number) + 8

            

Reported by Pylint.

Unused argument 'sfixed64'
Error

Line: 163 Column: 36

                return TagByteSize(field_number) + 4


def SFixed64ByteSize(field_number, sfixed64):
  return TagByteSize(field_number) + 8


def FloatByteSize(field_number, flt):
  return TagByteSize(field_number) + 4

            

Reported by Pylint.

Unused argument 'flt'
Error

Line: 167 Column: 33

                return TagByteSize(field_number) + 8


def FloatByteSize(field_number, flt):
  return TagByteSize(field_number) + 4


def DoubleByteSize(field_number, double):
  return TagByteSize(field_number) + 8

            

Reported by Pylint.

Unused argument 'double'
Error

Line: 171 Column: 34

                return TagByteSize(field_number) + 4


def DoubleByteSize(field_number, double):
  return TagByteSize(field_number) + 8


def BoolByteSize(field_number, b):
  return TagByteSize(field_number) + 1

            

Reported by Pylint.

Unused argument 'b'
Error

Line: 175 Column: 32

                return TagByteSize(field_number) + 8


def BoolByteSize(field_number, b):
  return TagByteSize(field_number) + 1


def EnumByteSize(field_number, enum):
  return UInt32ByteSize(field_number, enum)

            

Reported by Pylint.

Redefining name 'message' from outer scope (line 37)
Error

Line: 193 Column: 33

                        + len(b))


def GroupByteSize(field_number, message):
  return (2 * TagByteSize(field_number)  # START and END group.
          + message.ByteSize())


def MessageByteSize(field_number, message):

            

Reported by Pylint.

Redefining name 'message' from outer scope (line 37)
Error

Line: 198 Column: 35

                        + message.ByteSize())


def MessageByteSize(field_number, message):
  return (TagByteSize(field_number)
          + _VarUInt64ByteSizeNoTag(message.ByteSize())
          + message.ByteSize())



            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 75 Column: 1

              # We'll have to provide alternate implementations of AppendLittleEndian*() on
# any architectures where these checks fail.
if struct.calcsize(FORMAT_UINT32_LITTLE_ENDIAN) != 4:
  raise AssertionError('Format "I" is not a 32-bit number.')
if struct.calcsize(FORMAT_UINT64_LITTLE_ENDIAN) != 8:
  raise AssertionError('Format "Q" is not a 64-bit number.')


def PackTag(field_number, wire_type):

            

Reported by Pylint.

java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java
123 issues
Avoid throwing raw exception types.
Design

Line: 1317

                    case UINT64:
        return readUInt64();
      default:
        throw new RuntimeException("unsupported field type.");
    }
  }

  private void verifyPackedFixed32Length(int bytes) throws IOException {
    if ((bytes & FIXED32_MULTIPLE_MASK) != 0) {

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

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.

The class 'CodedInputStreamReader' has a total cyclomatic complexity of 341 (highest 19).
Design

Line: 48

              
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
final class CodedInputStreamReader implements Reader {
  private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
  private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 48

              
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
final class CodedInputStreamReader implements Reader {
  private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
  private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;

            

Reported by PMD.

Avoid really long classes.
Design

Line: 48

              
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
final class CodedInputStreamReader implements Reader {
  private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
  private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;

            

Reported by PMD.

The class 'CodedInputStreamReader' has a Modified Cyclomatic Complexity of 4 (Highest = 12).
Design

Line: 48

              
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
final class CodedInputStreamReader implements Reader {
  private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
  private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;

            

Reported by PMD.

The class 'CodedInputStreamReader' has a Standard Cyclomatic Complexity of 5 (Highest = 18).
Design

Line: 48

              
/** An adapter between the {@link Reader} interface and {@link CodedInputStream}. */
@ExperimentalApi
final class CodedInputStreamReader implements Reader {
  private static final int FIXED32_MULTIPLE_MASK = FIXED32_SIZE - 1;
  private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 53

                private static final int FIXED64_MULTIPLE_MASK = FIXED64_SIZE - 1;
  private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;
  private int tag;
  private int endGroupTag;
  private int nextTag = NEXT_TAG_UNSET;

  public static CodedInputStreamReader forCodedInput(CodedInputStream input) {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 54

                private static final int NEXT_TAG_UNSET = 0;

  private final CodedInputStream input;
  private int tag;
  private int endGroupTag;
  private int nextTag = NEXT_TAG_UNSET;

  public static CodedInputStreamReader forCodedInput(CodedInputStream input) {
    if (input.wrapper != null) {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 55

              
  private final CodedInputStream input;
  private int tag;
  private int endGroupTag;
  private int nextTag = NEXT_TAG_UNSET;

  public static CodedInputStreamReader forCodedInput(CodedInputStream input) {
    if (input.wrapper != null) {
      return input.wrapper;

            

Reported by PMD.

python/google/protobuf/internal/service_reflection_test.py
122 issues
No name 'unittest_pb2' in module 'google.protobuf'
Error

Line: 43 Column: 1

              except ImportError:
  import unittest

from google.protobuf import unittest_pb2
from google.protobuf import service_reflection
from google.protobuf import service


class FooUnitTest(unittest.TestCase):

            

Reported by Pylint.

Unused service_reflection imported from google.protobuf
Error

Line: 44 Column: 1

                import unittest

from google.protobuf import unittest_pb2
from google.protobuf import service_reflection
from google.protobuf import service


class FooUnitTest(unittest.TestCase):


            

Reported by Pylint.

Parameters differ from overridden 'CallMethod' method
Error

Line: 52 Column: 7

              
  def testService(self):
    class MockRpcChannel(service.RpcChannel):
      def CallMethod(self, method, controller, request, response, callback):
        self.method = method
        self.controller = controller
        self.request = request
        callback(response)


            

Reported by Pylint.

Attribute 'method' defined outside __init__
Error

Line: 53 Column: 9

                def testService(self):
    class MockRpcChannel(service.RpcChannel):
      def CallMethod(self, method, controller, request, response, callback):
        self.method = method
        self.controller = controller
        self.request = request
        callback(response)

    class MockRpcController(service.RpcController):

            

Reported by Pylint.

Attribute 'controller' defined outside __init__
Error

Line: 54 Column: 9

                  class MockRpcChannel(service.RpcChannel):
      def CallMethod(self, method, controller, request, response, callback):
        self.method = method
        self.controller = controller
        self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):

            

Reported by Pylint.

Attribute 'request' defined outside __init__
Error

Line: 55 Column: 9

                    def CallMethod(self, method, controller, request, response, callback):
        self.method = method
        self.controller = controller
        self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):
        self.failure_message = msg

            

Reported by Pylint.

Method 'Failed' is abstract in class 'RpcController' but is not overridden
Error

Line: 58 Column: 5

                      self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):
        self.failure_message = msg

    self.callback_response = None


            

Reported by Pylint.

Method 'Reset' is abstract in class 'RpcController' but is not overridden
Error

Line: 58 Column: 5

                      self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):
        self.failure_message = msg

    self.callback_response = None


            

Reported by Pylint.

Method 'StartCancel' is abstract in class 'RpcController' but is not overridden
Error

Line: 58 Column: 5

                      self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):
        self.failure_message = msg

    self.callback_response = None


            

Reported by Pylint.

Method 'ErrorText' is abstract in class 'RpcController' but is not overridden
Error

Line: 58 Column: 5

                      self.request = request
        callback(response)

    class MockRpcController(service.RpcController):
      def SetFailed(self, msg):
        self.failure_message = msg

    self.callback_response = None


            

Reported by Pylint.

conformance/conformance_python.py
118 issues
Unable to import 'google.protobuf'
Error

Line: 40 Column: 1

              import struct
import sys
import os
from google.protobuf import json_format
from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2

            

Reported by Pylint.

Unable to import 'google.protobuf'
Error

Line: 41 Column: 1

              import sys
import os
from google.protobuf import json_format
from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2


            

Reported by Pylint.

Unable to import 'google.protobuf'
Error

Line: 42 Column: 1

              import os
from google.protobuf import json_format
from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2

sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)

            

Reported by Pylint.

Unable to import 'google.protobuf'
Error

Line: 43 Column: 1

              from google.protobuf import json_format
from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2

sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)

            

Reported by Pylint.

Unable to import 'google.protobuf'
Error

Line: 44 Column: 1

              from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2

sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)


            

Reported by Pylint.

Unable to import 'conformance_pb2'
Error

Line: 45 Column: 1

              from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2

sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)

test_count = 0

            

Reported by Pylint.

TODO(gerbens): Remove, this is a hack to detect if the old vs new
Error

Line: 62 Column: 3

                if request.message_type == "conformance.FailureSet":
    failure_set = conformance_pb2.FailureSet()
    failures = []
    # TODO(gerbens): Remove, this is a hack to detect if the old vs new
    # parser is used by the cpp code. Relying on a bug in the old parser.
    hack_proto = test_messages_proto2_pb2.TestAllTypesProto2()
    old_parser = True
    try:
      hack_proto.ParseFromString(b"\322\002\001")

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 138 Column: 14

                              conformance_pb2.JSON_IGNORE_UNKNOWN_PARSING_TEST
        json_format.Parse(request.json_payload, test_message,
                          ignore_unknown_fields)
      except Exception as e:
        response.parse_error = str(e)
        return response

    elif request.WhichOneof('payload') == 'text_payload':
      try:

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 145 Column: 14

                  elif request.WhichOneof('payload') == 'text_payload':
      try:
        text_format.Parse(request.text_payload, test_message)
      except Exception as e:
        response.parse_error = str(e)
        return response

    else:
      raise ProtocolError("Request didn't have payload.")

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 161 Column: 14

                  elif request.requested_output_format == conformance_pb2.JSON:
      try:
        response.json_payload = json_format.MessageToJson(test_message)
      except Exception as e:
        response.serialize_error = str(e)
        return response

    elif request.requested_output_format == conformance_pb2.TEXT_FORMAT:
      response.text_payload = text_format.MessageToString(

            

Reported by Pylint.

java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java
111 issues
Avoid reassigning parameters such as 'lim'
Design

Line: 249

                 *     limit for numBytes
   */
  static void testBytes(
      ByteStringFactory factory, int numBytes, long expectedCount, long start, long lim) {
    Random rnd = new Random();
    byte[] bytes = new byte[numBytes];

    if (lim == -1) {
      lim = 1L << (numBytes * 8);

            

Reported by PMD.

System.out.println is used
Design

Line: 282

                      assertThat(Utf8.decodeUtf8(bytes, 0, numBytes)).isEqualTo(s);
      } catch (InvalidProtocolBufferException e) {
        if (isRoundTrippable) {
          System.out.println("Could not decode utf-8");
          outputFailure(byteChar, bytes, bytesReencoded);
        }
      }

      // Test partial sequences.

            

Reported by PMD.

System.out.printf is used
Design

Line: 300

                    int state2 = Utf8.partialIsValidUtf8(state1, bytes, i, j);
      int state3 = Utf8.partialIsValidUtf8(state2, bytes, j, numBytes);
      if (isRoundTrippable != (state3 == Utf8.COMPLETE)) {
        System.out.printf("state=%04x %04x %04x i=%d j=%d%n", state1, state2, state3, i, j);
        outputFailure(byteChar, bytes, bytesReencoded);
      }
      assertThat((state3 == Utf8.COMPLETE)).isEqualTo(isRoundTrippable);

      // Test ropes built out of small partial sequences

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 335

                    }
      count++;
      if (byteChar != 0 && byteChar % 1000000L == 0) {
        logger.info("Processed " + (byteChar / 1000000L) + " million characters");
      }
    }
    logger.info("Round tripped " + countRoundTripped + " of " + count);
    assertThat(countRoundTripped).isEqualTo(expectedCount);
  }

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 338

                      logger.info("Processed " + (byteChar / 1000000L) + " million characters");
      }
    }
    logger.info("Round tripped " + countRoundTripped + " of " + count);
    assertThat(countRoundTripped).isEqualTo(expectedCount);
  }

  /**
   * Variation of {@link #testBytes} that does less allocation using the low-level encoders/decoders

            

Reported by PMD.

Avoid reassigning parameters such as 'lim'
Design

Line: 356

                 *     limit for numBytes
   */
  static void testBytesUsingByteBuffers(
      ByteStringFactory factory, int numBytes, long expectedCount, long start, long lim) {
    CharsetDecoder decoder =
        Internal.UTF_8
            .newDecoder()
            .onMalformedInput(CodingErrorAction.REPLACE)
            .onUnmappableCharacter(CodingErrorAction.REPLACE);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 430

                      countRoundTripped++;
      }
      if (byteChar != 0 && byteChar % 1000000 == 0) {
        logger.info("Processed " + (byteChar / 1000000) + " million characters");
      }
    }
    logger.info("Round tripped " + countRoundTripped + " of " + count);
    assertThat(countRoundTripped).isEqualTo(expectedCount);
  }

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 433

                      logger.info("Processed " + (byteChar / 1000000) + " million characters");
      }
    }
    logger.info("Round tripped " + countRoundTripped + " of " + count);
    assertThat(countRoundTripped).isEqualTo(expectedCount);
  }

  private static void outputFailure(long byteChar, byte[] bytes, byte[] after) {
    outputFailure(byteChar, bytes, after, after.length);

            

Reported by PMD.

The class 'IsValidUtf8TestUtil' has a Standard Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 55

               * @author jonp@google.com (Jon Perlow)
 * @author martinrb@google.com (Martin Buchholz)
 */
final class IsValidUtf8TestUtil {
  private static final Logger logger = Logger.getLogger(IsValidUtf8TestUtil.class.getName());

  private IsValidUtf8TestUtil() {}

  static interface ByteStringFactory {

            

Reported by PMD.

The class 'IsValidUtf8TestUtil' has a Modified Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 55

               * @author jonp@google.com (Jon Perlow)
 * @author martinrb@google.com (Martin Buchholz)
 */
final class IsValidUtf8TestUtil {
  private static final Logger logger = Logger.getLogger(IsValidUtf8TestUtil.class.getName());

  private IsValidUtf8TestUtil() {}

  static interface ByteStringFactory {

            

Reported by PMD.

java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java
110 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 50

              @RunWith(JUnit4.class)
public class FieldMaskTreeTest {
  @Test
  public void testAddFieldPath() throws Exception {
    FieldMaskTree tree = new FieldMaskTree();
    assertThat(tree.toString()).isEmpty();
    tree.addFieldPath("");
    assertThat(tree.toString()).isEmpty();
    // New branch.

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 52

                @Test
  public void testAddFieldPath() throws Exception {
    FieldMaskTree tree = new FieldMaskTree();
    assertThat(tree.toString()).isEmpty();
    tree.addFieldPath("");
    assertThat(tree.toString()).isEmpty();
    // New branch.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 54

                  FieldMaskTree tree = new FieldMaskTree();
    assertThat(tree.toString()).isEmpty();
    tree.addFieldPath("");
    assertThat(tree.toString()).isEmpty();
    // New branch.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // Redundant path.
    tree.addFieldPath("foo");

            

Reported by PMD.

The String literal 'foo' appears 10 times in this file; the first occurrence is on line 56
Error

Line: 56

                  tree.addFieldPath("");
    assertThat(tree.toString()).isEmpty();
    // New branch.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // Redundant path.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // New branch.

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 57

                  assertThat(tree.toString()).isEmpty();
    // New branch.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // Redundant path.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // New branch.
    tree.addFieldPath("bar.baz");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 60

                  assertThat(tree.toString()).isEqualTo("foo");
    // Redundant path.
    tree.addFieldPath("foo");
    assertThat(tree.toString()).isEqualTo("foo");
    // New branch.
    tree.addFieldPath("bar.baz");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // Redundant sub-path.
    tree.addFieldPath("foo.bar");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 63

                  assertThat(tree.toString()).isEqualTo("foo");
    // New branch.
    tree.addFieldPath("bar.baz");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // Redundant sub-path.
    tree.addFieldPath("foo.bar");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // New branch from a non-root node.
    tree.addFieldPath("bar.quz");

            

Reported by PMD.

The String literal 'foo.bar' appears 4 times in this file; the first occurrence is on line 65
Error

Line: 65

                  tree.addFieldPath("bar.baz");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // Redundant sub-path.
    tree.addFieldPath("foo.bar");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // New branch from a non-root node.
    tree.addFieldPath("bar.quz");
    assertThat(tree.toString()).isEqualTo("bar.baz,bar.quz,foo");
    // A path that matches several existing sub-paths.

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 66

                  assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // Redundant sub-path.
    tree.addFieldPath("foo.bar");
    assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // New branch from a non-root node.
    tree.addFieldPath("bar.quz");
    assertThat(tree.toString()).isEqualTo("bar.baz,bar.quz,foo");
    // A path that matches several existing sub-paths.
    tree.addFieldPath("bar");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 69

                  assertThat(tree.toString()).isEqualTo("bar.baz,foo");
    // New branch from a non-root node.
    tree.addFieldPath("bar.quz");
    assertThat(tree.toString()).isEqualTo("bar.baz,bar.quz,foo");
    // A path that matches several existing sub-paths.
    tree.addFieldPath("bar");
    assertThat(tree.toString()).isEqualTo("bar,foo");
  }


            

Reported by PMD.

python/google/protobuf/internal/wire_format_test.py
105 issues
Bad indentation. Found 2 spaces, expected 4
Style

Line: 38 Column: 1

              __author__ = 'robinson@google.com (Will Robinson)'

try:
  import unittest2 as unittest  #PY26
except ImportError:
  import unittest

from google.protobuf import message
from google.protobuf.internal import wire_format

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 40 Column: 1

              try:
  import unittest2 as unittest  #PY26
except ImportError:
  import unittest

from google.protobuf import message
from google.protobuf.internal import wire_format



            

Reported by Pylint.

Missing class docstring
Error

Line: 46 Column: 1

              from google.protobuf.internal import wire_format


class WireFormatTest(unittest.TestCase):

  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 48 Column: 1

              
class WireFormatTest(unittest.TestCase):

  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 48 Column: 3

              
class WireFormatTest(unittest.TestCase):

  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag

            

Reported by Pylint.

Method name "testPackTag" doesn't conform to snake_case naming style
Error

Line: 48 Column: 3

              
class WireFormatTest(unittest.TestCase):

  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 49 Column: 1

              class WireFormatTest(unittest.TestCase):

  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag
    # Number too high.

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 50 Column: 1

              
  def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag
    # Number too high.
    self.assertRaises(message.EncodeError, PackTag, field_number, 6)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 51 Column: 1

                def testPackTag(self):
    field_number = 0xabc
    tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag
    # Number too high.
    self.assertRaises(message.EncodeError, PackTag, field_number, 6)
    # Number too low.

            

Reported by Pylint.

Variable name "PackTag" doesn't conform to snake_case naming style
Error

Line: 53 Column: 5

                  tag_type = 2
    self.assertEqual((field_number << 3) | tag_type,
                     wire_format.PackTag(field_number, tag_type))
    PackTag = wire_format.PackTag
    # Number too high.
    self.assertRaises(message.EncodeError, PackTag, field_number, 6)
    # Number too low.
    self.assertRaises(message.EncodeError, PackTag, field_number, -1)


            

Reported by Pylint.