The following issues were found

python/mox.py
551 issues
Module 'types' has no 'InstanceType' member
Error

Line: 155 Column: 40

              
  # A list of types that should be stubbed out with MockObjects (as
  # opposed to MockAnythings).
  _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType,
                      types.ObjectType, types.TypeType]

  def __init__(self):
    """Initialize a new Mox."""


            

Reported by Pylint.

Module 'types' has no 'ClassType' member
Error

Line: 155 Column: 23

              
  # A list of types that should be stubbed out with MockObjects (as
  # opposed to MockAnythings).
  _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType,
                      types.ObjectType, types.TypeType]

  def __init__(self):
    """Initialize a new Mox."""


            

Reported by Pylint.

Module 'types' has no 'ObjectType' member
Error

Line: 156 Column: 23

                # A list of types that should be stubbed out with MockObjects (as
  # opposed to MockAnythings).
  _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType,
                      types.ObjectType, types.TypeType]

  def __init__(self):
    """Initialize a new Mox."""

    self._mock_objects = []

            

Reported by Pylint.

Module 'types' has no 'TypeType' member
Error

Line: 156 Column: 41

                # A list of types that should be stubbed out with MockObjects (as
  # opposed to MockAnythings).
  _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType,
                      types.ObjectType, types.TypeType]

  def __init__(self):
    """Initialize a new Mox."""

    self._mock_objects = []

            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 72 Column: 3

              class Error(AssertionError):
  """Base exception for this module."""

  pass


class ExpectedMethodCallsError(Error):
  """Raised when Verify() is called before all expected methods have been called
  """

            

Reported by Pylint.

Access to a protected member _Replay of a client class
Error

Line: 193 Column: 7

                  """Set all mock objects to replay mode."""

    for mock_obj in self._mock_objects:
      mock_obj._Replay()


  def VerifyAll(self):
    """Call verify on all mock objects created."""


            

Reported by Pylint.

Access to a protected member _Verify of a client class
Error

Line: 200 Column: 7

                  """Call verify on all mock objects created."""

    for mock_obj in self._mock_objects:
      mock_obj._Verify()

  def ResetAll(self):
    """Call reset on all mock objects.  This does not unset stubs."""

    for mock_obj in self._mock_objects:

            

Reported by Pylint.

Access to a protected member _Reset of a client class
Error

Line: 206 Column: 7

                  """Call reset on all mock objects.  This does not unset stubs."""

    for mock_obj in self._mock_objects:
      mock_obj._Reset()

  def StubOutWithMock(self, obj, attr_name, use_mock_anything=False):
    """Replace a method, attribute, etc. with a Mock.

    This will replace a class or module with a MockObject, and everything else

            

Reported by Pylint.

Access to a protected member _Replay of a client class
Error

Line: 243 Column: 5

                """

  for mock in args:
    mock._Replay()


def Verify(*args):
  """Verify mocks.


            

Reported by Pylint.

Access to a protected member _Verify of a client class
Error

Line: 254 Column: 5

                """

  for mock in args:
    mock._Verify()


def Reset(*args):
  """Reset mocks.


            

Reported by Pylint.

python/google/protobuf/json_format.py
539 issues
Bad option value 'g-import-not-at-top'
Error

Line: 45 Column: 1

              
__author__ = 'jieluo@google.com (Jie Luo)'

# pylint: disable=g-statement-before-imports,g-import-not-at-top
try:
  from collections import OrderedDict
except ImportError:
  from ordereddict import OrderedDict  # PY26
# pylint: enable=g-statement-before-imports,g-import-not-at-top

            

Reported by Pylint.

Bad option value 'g-statement-before-imports'
Error

Line: 45 Column: 1

              
__author__ = 'jieluo@google.com (Jie Luo)'

# pylint: disable=g-statement-before-imports,g-import-not-at-top
try:
  from collections import OrderedDict
except ImportError:
  from ordereddict import OrderedDict  # PY26
# pylint: enable=g-statement-before-imports,g-import-not-at-top

            

Reported by Pylint.

Bad option value 'g-import-not-at-top'
Error

Line: 50 Column: 1

                from collections import OrderedDict
except ImportError:
  from ordereddict import OrderedDict  # PY26
# pylint: enable=g-statement-before-imports,g-import-not-at-top

import base64
import json
import math


            

Reported by Pylint.

Bad option value 'g-statement-before-imports'
Error

Line: 50 Column: 1

                from collections import OrderedDict
except ImportError:
  from ordereddict import OrderedDict  # PY26
# pylint: enable=g-statement-before-imports,g-import-not-at-top

import base64
import json
import math


            

Reported by Pylint.

Unused import sys
Error

Line: 59 Column: 1

              from operator import methodcaller

import re
import sys

import six

from google.protobuf.internal import type_checkers
from google.protobuf import descriptor

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 277 Column: 7

                          js[name] = self._FieldToJsonObject(field, field.default_value)

    except ValueError as e:
      raise SerializeToJsonError(
          'Failed to serialize {0} field: {1}.'.format(field.name, e))

    return js

  def _FieldToJsonObject(self, field, value):

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 407 Column: 5

                try:
    message_descriptor = pool.FindMessageTypeByName(type_name)
  except KeyError:
    raise TypeError(
        'Can not find message descriptor by type_url: {0}.'.format(type_url))
  message_class = db.GetPrototype(message_descriptor)
  return message_class()



            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 433 Column: 5

                try:
    js = json.loads(text, object_pairs_hook=_DuplicateChecker)
  except ValueError as e:
    raise ParseError('Failed to load JSON: {0}.'.format(str(e)))
  return ParseDict(js, message, ignore_unknown_fields, descriptor_pool)


def ParseDict(js_dict,
              message,

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 597 Column: 11

                          setattr(message, field.name, _ConvertScalarFieldValue(value, field))
      except ParseError as e:
        if field and field.containing_oneof is None:
          raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
        else:
          raise ParseError(str(e))
      except ValueError as e:
        raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
      except TypeError as e:

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 599 Column: 11

                      if field and field.containing_oneof is None:
          raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
        else:
          raise ParseError(str(e))
      except ValueError as e:
        raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))
      except TypeError as e:
        raise ParseError('Failed to parse {0} field: {1}.'.format(name, e))


            

Reported by Pylint.

python/google/protobuf/internal/containers.py
530 issues
Value 'self' is unsubscriptable
Error

Line: 78 Column: 16

              
    def get(self, key, default=None):
      try:
        return self[key]
      except KeyError:
        return default

    def __contains__(self, key):
      try:

            

Reported by Pylint.

Value 'self' is unsubscriptable
Error

Line: 84 Column: 9

              
    def __contains__(self, key):
      try:
        self[key]
      except KeyError:
        return False
      else:
        return True


            

Reported by Pylint.

Non-iterable value self is used in an iterating context
Error

Line: 94 Column: 18

                    return iter(self)

    def itervalues(self):
      for key in self:
        yield self[key]

    def iteritems(self):
      for key in self:
        yield (key, self[key])

            

Reported by Pylint.

Value 'self' is unsubscriptable
Error

Line: 95 Column: 15

              
    def itervalues(self):
      for key in self:
        yield self[key]

    def iteritems(self):
      for key in self:
        yield (key, self[key])


            

Reported by Pylint.

Non-iterable value self is used in an iterating context
Error

Line: 98 Column: 18

                      yield self[key]

    def iteritems(self):
      for key in self:
        yield (key, self[key])

    def keys(self):
      return list(self)


            

Reported by Pylint.

Value 'self' is unsubscriptable
Error

Line: 99 Column: 21

              
    def iteritems(self):
      for key in self:
        yield (key, self[key])

    def keys(self):
      return list(self)

    def items(self):

            

Reported by Pylint.

Value 'self' is unsubscriptable
Error

Line: 105 Column: 21

                    return list(self)

    def items(self):
      return [(key, self[key]) for key in self]

    def values(self):
      return [self[key] for key in self]

    # Mappings are not hashable by default, but subclasses can change this

            

Reported by Pylint.

Non-iterable value self is used in an iterating context
Error

Line: 105 Column: 43

                    return list(self)

    def items(self):
      return [(key, self[key]) for key in self]

    def values(self):
      return [self[key] for key in self]

    # Mappings are not hashable by default, but subclasses can change this

            

Reported by Pylint.

Value 'self' is unsubscriptable
Error

Line: 108 Column: 15

                    return [(key, self[key]) for key in self]

    def values(self):
      return [self[key] for key in self]

    # Mappings are not hashable by default, but subclasses can change this
    __hash__ = None

    def __eq__(self, other):

            

Reported by Pylint.

Non-iterable value self is used in an iterating context
Error

Line: 108 Column: 36

                    return [(key, self[key]) for key in self]

    def values(self):
      return [self[key] for key in self]

    # Mappings are not hashable by default, but subclasses can change this
    __hash__ = None

    def __eq__(self, other):

            

Reported by Pylint.

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

Line: 608

              
      // If we make it here, the runtime still lies about what we know to be true at compile
      // time. We throw to alert server monitoring for further remediation.
      throw new RuntimeException(
          "Field "
              + fieldName
              + " for "
              + messageClass.getName()
              + " not found. Known fields are "

            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 1180

                @Override
  public void mergeFrom(T message, T other) {
    if (other == null) {
      throw new NullPointerException();
    }
    for (int i = 0; i < buffer.length; i += INTS_PER_FIELD) {
      // A separate method allows for better JIT optimizations
      mergeSingleField(message, other, i);
    }

            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 3854

                public void mergeFrom(T message, Reader reader, ExtensionRegistryLite extensionRegistry)
      throws IOException {
    if (extensionRegistry == null) {
      throw new NullPointerException();
    }
    mergeFromHelper(unknownFieldSchema, extensionSchema, message, reader, extensionRegistry);
  }

  /**

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 4417

                      position = decodeStringRequireUtf8(data, position, registers);
        break;
      default:
        throw new RuntimeException("unsupported field type.");
    }
    return position;
  }

  /** Decodes a map entry. */

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 5542

                        MapEntryLite.writeTo(codedOutput, metadata, entry.getKey(), entry.getValue());
        } catch (IOException e) {
          // Writing to ByteString CodedOutputStream should not throw IOException.
          throw new RuntimeException(e);
        }
        unknownFieldSchema.addLengthDelimited(unknownFields, number, codedBuilder.build());
        it.remove();
      }
    }

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 4357

                /** Decodes a map entry key or value. Stores result in registers.object1. */
  private int decodeMapEntryValue(
      byte[] data,
      int position,
      int limit,
      WireFormat.FieldType fieldType,
      Class<?> messageType,
      Registers registers)
      throws IOException {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 4357

                /** Decodes a map entry key or value. Stores result in registers.object1. */
  private int decodeMapEntryValue(
      byte[] data,
      int position,
      int limit,
      WireFormat.FieldType fieldType,
      Class<?> messageType,
      Registers registers)
      throws IOException {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 4357

                /** Decodes a map entry key or value. Stores result in registers.object1. */
  private int decodeMapEntryValue(
      byte[] data,
      int position,
      int limit,
      WireFormat.FieldType fieldType,
      Class<?> messageType,
      Registers registers)
      throws IOException {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 4357

                /** Decodes a map entry key or value. Stores result in registers.object1. */
  private int decodeMapEntryValue(
      byte[] data,
      int position,
      int limit,
      WireFormat.FieldType fieldType,
      Class<?> messageType,
      Registers registers)
      throws IOException {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 4357

                /** Decodes a map entry key or value. Stores result in registers.object1. */
  private int decodeMapEntryValue(
      byte[] data,
      int position,
      int limit,
      WireFormat.FieldType fieldType,
      Class<?> messageType,
      Registers registers)
      throws IOException {

            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/MapLiteTest.java
495 issues
Possible God Class (WMC=73, ATFD=242, TCC=0.000%)
Design

Line: 51

              
/** Unit tests for map fields. */
@RunWith(JUnit4.class)
public final class MapLiteTest {

  private void setMapValues(TestMap.Builder builder) {
    builder
        .putInt32ToInt32Field(1, 11)
        .putInt32ToInt32Field(2, 22)

            

Reported by PMD.

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

Line: 51

              
/** Unit tests for map fields. */
@RunWith(JUnit4.class)
public final class MapLiteTest {

  private void setMapValues(TestMap.Builder builder) {
    builder
        .putInt32ToInt32Field(1, 11)
        .putInt32ToInt32Field(2, 22)

            

Reported by PMD.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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.

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

Line: 54

              public final class MapLiteTest {

  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/CodedInputStreamTest.java
495 issues
Avoid reassigning parameters such as 'blockSize'
Design

Line: 90

                  },
    ITER_DIRECT {
      @Override
      CodedInputStream newDecoder(byte[] data, int blockSize) {
        if (blockSize > DEFAULT_BLOCK_SIZE) {
          blockSize = DEFAULT_BLOCK_SIZE;
        }
        ArrayList<ByteBuffer> input = new ArrayList<ByteBuffer>();
        for (int i = 0; i < data.length; i += blockSize) {

            

Reported by PMD.

Avoid reassigning parameters such as 'blockSize'
Design

Line: 107

                  },
    STREAM_ITER_DIRECT {
      @Override
      CodedInputStream newDecoder(byte[] data, int blockSize) {
        if (blockSize > DEFAULT_BLOCK_SIZE) {
          blockSize = DEFAULT_BLOCK_SIZE;
        }
        ArrayList<ByteBuffer> input = new ArrayList<ByteBuffer>();
        for (int i = 0; i < data.length; i += blockSize) {

            

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.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertArrayEquals;
import protobuf_unittest.UnittestProto.BoolMessage;

            

Reported by PMD.

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

Line: 56

              
/** Unit test for {@link CodedInputStream}. */
@RunWith(JUnit4.class)
public class CodedInputStreamTest {

  private static final int DEFAULT_BLOCK_SIZE = 4096;

  private enum InputType {
    ARRAY {

            

Reported by PMD.

Possible God Class (WMC=127, ATFD=116, TCC=0.000%)
Design

Line: 56

              
/** Unit test for {@link CodedInputStream}. */
@RunWith(JUnit4.class)
public class CodedInputStreamTest {

  private static final int DEFAULT_BLOCK_SIZE = 4096;

  private enum InputType {
    ARRAY {

            

Reported by PMD.

The class 'CodedInputStreamTest' has a total cyclomatic complexity of 127 (highest 8).
Design

Line: 56

              
/** Unit test for {@link CodedInputStream}. */
@RunWith(JUnit4.class)
public class CodedInputStreamTest {

  private static final int DEFAULT_BLOCK_SIZE = 4096;

  private enum InputType {
    ARRAY {

            

Reported by PMD.

Avoid really long classes.
Design

Line: 56

              
/** Unit test for {@link CodedInputStream}. */
@RunWith(JUnit4.class)
public class CodedInputStreamTest {

  private static final int DEFAULT_BLOCK_SIZE = 4096;

  private enum InputType {
    ARRAY {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 77

                    @Override
      CodedInputStream newDecoder(byte[] data, int blockSize) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
        buffer.put(data);
        buffer.flip();
        return CodedInputStream.newInstance(buffer);
      }
    },
    STREAM {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 78

                    CodedInputStream newDecoder(byte[] data, int blockSize) {
        ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
        buffer.put(data);
        buffer.flip();
        return CodedInputStream.newInstance(buffer);
      }
    },
    STREAM {
      @Override

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 98

                      for (int i = 0; i < data.length; i += blockSize) {
          int rl = Math.min(blockSize, data.length - i);
          ByteBuffer rb = ByteBuffer.allocateDirect(rl);
          rb.put(data, i, rl);
          rb.flip();
          input.add(rb);
        }
        return CodedInputStream.newInstance(input);
      }

            

Reported by PMD.

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

Line: 3771

                  try {
      ancestor = ancestor.getCanonicalFile();
    } catch (IOException e) {
      throw new RuntimeException("Couldn't get canonical name of working directory.", e);
    }

    String srcRootCheck = "src/google/protobuf";

    // If we're running w/ Bazel on Windows, we're not in a sandbox, so we

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 3791

                    ancestor = ancestor.getParentFile();
    }

    throw new RuntimeException(
        "Could not find golden files.  This test must be run from within the "
            + "protobuf source package so that it can read test data files from the "
            + "C++ source tree: "
            + initialPath);
  }

            

Reported by PMD.

Avoid throwing raw exception types.
Design

Line: 3819

                    return ByteString.copyFrom(
          com.google.common.io.ByteStreams.toByteArray(TestUtil.class.getResourceAsStream(name)));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  /**
   * Get the bytes of the "golden message". This is a serialized TestAllTypes with all fields set as

            

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.UnittestLite.defaultBoolExtensionLite;
import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite;
import static com.google.protobuf.UnittestLite.defaultCordExtensionLite;
import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite;

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
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.UnittestLite.defaultBoolExtensionLite;
import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite;
import static com.google.protobuf.UnittestLite.defaultCordExtensionLite;
import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite;

            

Reported by PMD.

The class 'TestUtil' has a Standard Cyclomatic Complexity of 2 (Highest = 26).
Design

Line: 254

               *
 * @author kenton@google.com Kenton Varda
 */
public final class TestUtil {
  private TestUtil() {}

  public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
      TestRequired.newBuilder().setA(1).buildPartial();
  public static final TestRequired TEST_REQUIRED_INITIALIZED =

            

Reported by PMD.

Avoid really long classes.
Design

Line: 254

               *
 * @author kenton@google.com Kenton Varda
 */
public final class TestUtil {
  private TestUtil() {}

  public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
      TestRequired.newBuilder().setA(1).buildPartial();
  public static final TestRequired TEST_REQUIRED_INITIALIZED =

            

Reported by PMD.

Possible God Class (WMC=93, ATFD=1,469, TCC=0.000%)
Design

Line: 254

               *
 * @author kenton@google.com Kenton Varda
 */
public final class TestUtil {
  private TestUtil() {}

  public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
      TestRequired.newBuilder().setA(1).buildPartial();
  public static final TestRequired TEST_REQUIRED_INITIALIZED =

            

Reported by PMD.

The class 'TestUtil' has a Modified Cyclomatic Complexity of 1 (Highest = 17).
Design

Line: 254

               *
 * @author kenton@google.com Kenton Varda
 */
public final class TestUtil {
  private TestUtil() {}

  public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
      TestRequired.newBuilder().setA(1).buildPartial();
  public static final TestRequired TEST_REQUIRED_INITIALIZED =

            

Reported by PMD.

The class 'TestUtil' has a NCSS line count of 2607 (Highest = 176).
Design

Line: 254

               *
 * @author kenton@google.com Kenton Varda
 */
public final class TestUtil {
  private TestUtil() {}

  public static final TestRequired TEST_REQUIRED_UNINITIALIZED =
      TestRequired.newBuilder().setA(1).buildPartial();
  public static final TestRequired TEST_REQUIRED_INITIALIZED =

            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/TextFormatTest.java
472 issues
A high number of imports can indicate a high degree of coupling within an object.
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.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.protobuf.TestUtil.TEST_REQUIRED_INITIALIZED;
import static com.google.protobuf.TestUtil.TEST_REQUIRED_UNINITIALIZED;

            

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.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.protobuf.TestUtil.TEST_REQUIRED_INITIALIZED;
import static com.google.protobuf.TestUtil.TEST_REQUIRED_UNINITIALIZED;

            

Reported by PMD.

The class 'TextFormatTest' has a total cyclomatic complexity of 111 (highest 13).
Design

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

Possible God Class (WMC=111, ATFD=156, TCC=2.073%)
Design

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

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

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

Avoid really long classes.
Design

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

The class 'TextFormatTest' has a Standard Cyclomatic Complexity of 2 (Highest = 13).
Design

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

The class 'TextFormatTest' has a Modified Cyclomatic Complexity of 2 (Highest = 13).
Design

Line: 73

               * <p>TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
 */
@RunWith(JUnit4.class)
public class TextFormatTest {

  // A basic string with different escapable characters for testing.
  private static final String ESCAPE_TEST_STRING =
      "\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\";


            

Reported by PMD.

Do not add empty strings
Performance

Line: 90

                    TestUtil.readTextFromFile("text_format_unittest_extensions_data.txt");

  private static final String EXOTIC_TEXT =
      ""
          + "repeated_int32: -1\n"
          + "repeated_int32: -2147483648\n"
          + "repeated_int64: -1,\n"
          + "repeated_int64: -9223372036854775808\n"
          + "repeated_uint32: 4294967295\n"

            

Reported by PMD.

Do not add empty strings
Performance

Line: 129

                        .replace(",", "");

  private static final String MESSAGE_SET_TEXT =
      ""
          + "[protobuf_unittest.TestMessageSetExtension1] {\n"
          + "  i: 123\n"
          + "}\n"
          + "[protobuf_unittest.TestMessageSetExtension2] {\n"
          + "  str: \"foo\"\n"

            

Reported by PMD.

objectivec/DevTools/pddm.py
453 issues
Assigning result of a function call, where the function has no return
Error

Line: 477 Column: 7

              
    @property
    def lines(self):
      captured_lines = SourceFile.SectionBase.lines.fget(self)
      directive_len = len('//%PDDM-EXPAND')
      result = []
      for line in captured_lines:
        result.append(line)
        if self._macro_collection:

            

Reported by Pylint.

Instance of 'PDDMError' has no 'message' member
Error

Line: 497 Column: 30

                        except PDDMError as e:
            raise PDDMError('%s\n...while expanding "%s" from the section'
                            ' that started:\n   Line %d: %s' %
                            (e.message, macro,
                             self.first_line_num, self.first_line))

      # Add the ending marker.
      if len(captured_lines) == 1:
        result.append('//%%PDDM-EXPAND-END %s' %

            

Reported by Pylint.

Instance of 'PDDMError' has no 'message' member
Error

Line: 533 Column: 28

                      except PDDMError as e:
          raise PDDMError('%s\n...while parsing section that started:\n'
                          '  Line %d: %s' %
                          (e.message, self.first_line_num, self.first_line))

  class ImportDefinesSection(SectionBase):
    """Section containing an import of PDDM-DEFINES from an external file."""

    def __init__(self, first_line_num, import_resolver):

            

Reported by Pylint.

Instance of 'PDDMError' has no 'message' member
Error

Line: 569 Column: 26

                    except PDDMError as e:
        raise PDDMError('%s\n...while importing defines:\n'
                        '  Line %d: %s' %
                        (e.message, self.first_line_num, self.first_line))

  def _ParseFile(self):
    self._sections = []
    lines = self._original_content.splitlines()
    cur_section = None

            

Reported by Pylint.

Instance of 'PDDMError' has no 'message' member
Error

Line: 671 Column: 25

                    src_file.ProcessContent(strip_expansion=opts.collapse)
    except PDDMError as e:
      sys.stderr.write('ERROR: %s\n...While processing "%s"\n' %
                       (e.message, a_path))
      return 101

    if src_file.processed_content != src_file.original_content:
      if not opts.dry_run:
        print('Updating for "%s".' % a_path)

            

Reported by Pylint.

Uses of a deprecated module 'optparse'
Error

Line: 104 Column: 1

              
"""

import optparse
import os
import re
import sys



            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 137 Column: 3

              
class PDDMError(Exception):
  """Error thrown by pddm."""
  pass


class MacroCollection(object):
  """Hold a set of macros and can resolve/expand them."""


            

Reported by Pylint.

Unused variable 'prev_macro_ref'
Error

Line: 289 Column: 20

                  if macro_ref_str is None:
      macro_ref_str = macro_ref_match.group('macro_ref')
    name = macro_ref_match.group('name')
    for prev_name, prev_macro_ref in macro_stack:
      if name == prev_name:
        raise PDDMError('Found macro recursion, invoking "%s":%s' %
                        (macro_ref_str, self._FormatStack(macro_stack)))
    macro = self._macros[name]
    args_str = macro_ref_match.group('args').strip()

            

Reported by Pylint.

Unused argument 'line_num'
Error

Line: 386 Column: 31

                    self._lines = []
      self._first_line_num = first_line_num

    def TryAppend(self, line, line_num):
      """Try appending a line.

      Args:
        line: The line to append.
        line_num: The number of the line.

            

Reported by Pylint.

Unused argument 'line'
Error

Line: 386 Column: 25

                    self._lines = []
      self._first_line_num = first_line_num

    def TryAppend(self, line, line_num):
      """Try appending a line.

      Args:
        line: The line to append.
        line_num: The number of the line.

            

Reported by Pylint.

java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
423 issues
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.util;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import com.google.common.collect.ImmutableSet;

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
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.util;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import com.google.common.collect.ImmutableSet;

            

Reported by PMD.

Avoid really long classes.
Design

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

Possible God Class (WMC=92, ATFD=176, TCC=0.000%)
Design

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

The class 'JsonFormatTest' has a total cyclomatic complexity of 92 (highest 12).
Design

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

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

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

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

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

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

Line: 87

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class JsonFormatTest {
  public JsonFormatTest() {
    // Test that locale does not affect JsonFormat.
    Locale.setDefault(Locale.forLanguageTag("hi-IN"));
  }


            

Reported by PMD.

Do not start a literal by 0 unless its an octal value
Error

Line: 134

                  builder.addRepeatedInt64(234567890123456789L);
    builder.addRepeatedUint32(678);
    builder.addRepeatedUint64(345678901234567890L);
    builder.addRepeatedSint32(012);
    builder.addRepeatedSint64(456789012345678901L);
    builder.addRepeatedFixed32(456);
    builder.addRepeatedFixed64(567890123456789012L);
    builder.addRepeatedSfixed32(890);
    builder.addRepeatedSfixed64(678901234567890123L);

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 149

                  builder.addRepeatedNestedMessageBuilder().setValue(200);
  }

  private void assertRoundTripEquals(Message message) throws Exception {
    assertRoundTripEquals(message, TypeRegistry.getEmptyTypeRegistry());
  }

  private void assertRoundTripEquals(Message message, TypeRegistry registry) throws Exception {
    JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);

            

Reported by PMD.