The following issues were found

objectivec/DevTools/pddm_tests.py
269 issues
Instance of 'PDDMError' has no 'message' member
Error

Line: 124 Column: 25

                      result = pddm.MacroCollection(f)
        self.fail('Should throw exception, entry %d' % idx)
      except pddm.PDDMError as e:
        self.assertTrue(e.message.startswith(expected_prefix),
                        'Entry %d failed: %r' % (idx, e))

  def testParseBeginIssues(self):
    test_list = [
      # 1. No name

            

Reported by Pylint.

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

Line: 179 Column: 25

                      result = pddm.MacroCollection(f)
        self.fail('Should throw exception, entry %d' % idx)
      except pddm.PDDMError as e:
        self.assertTrue(e.message.startswith(expected_prefix),
                        'Entry %d failed: %r' % (idx, e))


class TestExpandingMacros(unittest.TestCase):


            

Reported by Pylint.

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

Line: 272 Column: 26

                      result = mc.Expand(input_str)
        self.fail('Should throw exception, entry %d' % idx)
      except pddm.PDDMError as e:
        self.assertEqual(e.message, expected_err,
                        'Entry %d failed: %r' % (idx, e))

  def testExpandReferences(self):
    f = io.StringIO(u"""
PDDM-DEFINE StartIt()

            

Reported by Pylint.

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

Line: 316 Column: 24

                    result = mc.Expand('foo(A,B)')
      self.fail('Should throw exception! Test failed to catch recursion.')
    except pddm.PDDMError as e:
      self.assertEqual(e.message,
                       'Found macro recursion, invoking "foo(1, A)":\n...while expanding "bar(1, A)".\n...while expanding "foo(A,B)".')


class TestParsingSource(unittest.TestCase):


            

Reported by Pylint.

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

Line: 391 Column: 26

                      pddm.SourceFile(f)._ParseFile()
        self.fail('Should throw exception, entry %d' % idx)
      except pddm.PDDMError as e:
        self.assertEqual(e.message, expected_err,
                        'Entry %d failed: %r' % (idx, e))

class TestProcessingSource(unittest.TestCase):

  def testBasics(self):

            

Reported by Pylint.

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

Line: 495 Column: 24

                    sf.ProcessContent()
      self.fail('Should throw exception! Test failed to catch macro parsing error.')
    except pddm.PDDMError as e:
      self.assertEqual(e.message,
                       'Attempt to redefine macro: "PDDM-DEFINE mumble(x_)"\n'
                       '...while parsing section that started:\n'
                       '  Line 3: //%PDDM-DEFINE mumble(a_)')

  def testProcessFileWithExpandError(self):

            

Reported by Pylint.

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

Line: 515 Column: 24

                    sf.ProcessContent()
      self.fail('Should throw exception! Test failed to catch expand error.')
    except pddm.PDDMError as e:
      self.assertEqual(e.message,
                       'No macro named "foobar".\n'
                       '...while expanding "foobar(x_)" from the section that'
                       ' started:\n   Line 5: //%PDDM-EXPAND foobar(x_)')



            

Reported by Pylint.

Access to a protected member _macros of a client class
Error

Line: 46 Column: 26

                def testParseEmpty(self):
    f = io.StringIO(u'')
    result = pddm.MacroCollection(f)
    self.assertEqual(len(result._macros), 0)

  def testParseOne(self):
    f = io.StringIO(u"""PDDM-DEFINE foo( )
body""")
    result = pddm.MacroCollection(f)

            

Reported by Pylint.

Access to a protected member _macros of a client class
Error

Line: 52 Column: 26

                  f = io.StringIO(u"""PDDM-DEFINE foo( )
body""")
    result = pddm.MacroCollection(f)
    self.assertEqual(len(result._macros), 1)
    macro = result._macros.get('foo')
    self.assertIsNotNone(macro)
    self.assertEquals(macro.name, 'foo')
    self.assertEquals(macro.args, tuple())
    self.assertEquals(macro.body, 'body')

            

Reported by Pylint.

Access to a protected member _macros of a client class
Error

Line: 53 Column: 13

              body""")
    result = pddm.MacroCollection(f)
    self.assertEqual(len(result._macros), 1)
    macro = result._macros.get('foo')
    self.assertIsNotNone(macro)
    self.assertEquals(macro.name, 'foo')
    self.assertEquals(macro.args, tuple())
    self.assertEquals(macro.body, 'body')


            

Reported by Pylint.

java/core/src/main/java/com/google/protobuf/CodedInputStream.java
254 issues
Return an empty array rather than null.
Error

Line: 2924

                   * 
     * Returns a byte[] that may have escaped to user code via InputStream APIs.
     */
    private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException {
      if (size == 0) {
        return Internal.EMPTY_BYTE_ARRAY;
      }
      if (size < 0) {
        throw InvalidProtocolBufferException.negativeSize();

            

Reported by PMD.

Avoid reassigning parameters such as 'byteLimit'
Design

Line: 1186

                  }

    @Override
    public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
      if (byteLimit < 0) {
        throw InvalidProtocolBufferException.negativeSize();
      }
      byteLimit += getTotalBytesRead();
      if (byteLimit < 0) {

            

Reported by PMD.

Avoid reassigning parameters such as 'byteLimit'
Design

Line: 1910

                  }

    @Override
    public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
      if (byteLimit < 0) {
        throw InvalidProtocolBufferException.negativeSize();
      }
      byteLimit += getTotalBytesRead();
      final int oldLimit = currentLimit;

            

Reported by PMD.

Avoid reassigning parameters such as 'byteLimit'
Design

Line: 2703

                  }

    @Override
    public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
      if (byteLimit < 0) {
        throw InvalidProtocolBufferException.negativeSize();
      }
      byteLimit += totalBytesRetired + pos;
      final int oldLimit = currentLimit;

            

Reported by PMD.

Avoid reassigning parameters such as 'sizeLeft'
Design

Line: 2982

                   * 
     * Returns a byte[] that may have escaped to user code via InputStream APIs.
     */
    private List<byte[]> readRawBytesSlowPathRemainingChunks(int sizeLeft) throws IOException {
      // The size is very large.  For security reasons, we can't allocate the
      // entire byte array yet.  The size comes directly from the input, so a
      // maliciously-crafted message could provide a bogus very large size in
      // order to trick the app into allocating a lot of memory.  We avoid this
      // by allocating and reading only a small chunk at a time, so that the

            

Reported by PMD.

Avoid reassigning parameters such as 'byteLimit'
Design

Line: 3787

                  }

    @Override
    public int pushLimit(int byteLimit) throws InvalidProtocolBufferException {
      if (byteLimit < 0) {
        throw InvalidProtocolBufferException.negativeSize();
      }
      byteLimit += getTotalBytesRead();
      final int oldLimit = currentLimit;

            

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.Internal.EMPTY_BYTE_ARRAY;
import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER;
import static com.google.protobuf.Internal.UTF_8;
import static com.google.protobuf.Internal.checkNotNull;

            

Reported by PMD.

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

Line: 62

               *
 * @author kenton@google.com Kenton Varda
 */
public abstract class CodedInputStream {
  private static final int DEFAULT_BUFFER_SIZE = 4096;
  // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
  private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
  private static volatile int defaultRecursionLimit = 100;


            

Reported by PMD.

Avoid really long classes.
Design

Line: 62

               *
 * @author kenton@google.com Kenton Varda
 */
public abstract class CodedInputStream {
  private static final int DEFAULT_BUFFER_SIZE = 4096;
  // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
  private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
  private static volatile int defaultRecursionLimit = 100;


            

Reported by PMD.

The class 'CodedInputStream' has a NCSS line count of 1971 (Highest = 19).
Design

Line: 62

               *
 * @author kenton@google.com Kenton Varda
 */
public abstract class CodedInputStream {
  private static final int DEFAULT_BUFFER_SIZE = 4096;
  // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
  private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
  private static volatile int defaultRecursionLimit = 100;


            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
254 issues
Possible God Class (WMC=67, ATFD=56, TCC=0.000%)
Design

Line: 53

              
/** Unit test for {@link CodedOutputStream}. */
@RunWith(JUnit4.class)
public class CodedOutputStreamTest {
  private interface Coder {
    CodedOutputStream stream();

    byte[] toByteArray();


            

Reported by PMD.

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

Line: 53

              
/** Unit test for {@link CodedOutputStream}. */
@RunWith(JUnit4.class)
public class CodedOutputStreamTest {
  private interface Coder {
    CodedOutputStream stream();

    byte[] toByteArray();


            

Reported by PMD.

Field stream has the same name as a method
Error

Line: 63

                }

  private static final class OutputStreamCoder implements Coder {
    private final CodedOutputStream stream;
    private final ByteArrayOutputStream output;

    OutputStreamCoder(int size) {
      output = new ByteArrayOutputStream();
      stream = CodedOutputStream.newInstance(output, size);

            

Reported by PMD.

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

Line: 63

                }

  private static final class OutputStreamCoder implements Coder {
    private final CodedOutputStream stream;
    private final ByteArrayOutputStream output;

    OutputStreamCoder(int size) {
      output = new ByteArrayOutputStream();
      stream = CodedOutputStream.newInstance(output, size);

            

Reported by PMD.

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

Line: 64

              
  private static final class OutputStreamCoder implements Coder {
    private final CodedOutputStream stream;
    private final ByteArrayOutputStream output;

    OutputStreamCoder(int size) {
      output = new ByteArrayOutputStream();
      stream = CodedOutputStream.newInstance(output, size);
    }

            

Reported by PMD.

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

Line: 88

                }

  private static final class ArrayCoder implements Coder {
    private final CodedOutputStream stream;
    private final byte[] bytes;

    ArrayCoder(int size) {
      bytes = new byte[size];
      stream = CodedOutputStream.newInstance(bytes);

            

Reported by PMD.

Field stream has the same name as a method
Error

Line: 88

                }

  private static final class ArrayCoder implements Coder {
    private final CodedOutputStream stream;
    private final byte[] bytes;

    ArrayCoder(int size) {
      bytes = new byte[size];
      stream = CodedOutputStream.newInstance(bytes);

            

Reported by PMD.

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

Line: 89

              
  private static final class ArrayCoder implements Coder {
    private final CodedOutputStream stream;
    private final byte[] bytes;

    ArrayCoder(int size) {
      bytes = new byte[size];
      stream = CodedOutputStream.newInstance(bytes);
    }

            

Reported by PMD.

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

Line: 113

                }

  private static final class NioHeapCoder implements Coder {
    private final CodedOutputStream stream;
    private final ByteBuffer buffer;
    private final int initialPosition;

    NioHeapCoder(int size) {
      this(size, 0);

            

Reported by PMD.

Field stream has the same name as a method
Error

Line: 113

                }

  private static final class NioHeapCoder implements Coder {
    private final CodedOutputStream stream;
    private final ByteBuffer buffer;
    private final int initialPosition;

    NioHeapCoder(int size) {
      this(size, 0);

            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/NioByteStringTest.java
252 issues
Avoid reassigning parameters such as 'n'
Design

Line: 311

                 * @throws EOFException if this stream reaches the end before skipping all the bytes
   * @throws IOException if an I/O error occurs, or the stream does not support skipping
   */
  static void skipFully(InputStream in, long n) throws IOException {
    long toSkip = n;
    while (n > 0) {
      long amt = in.skip(n);
      if (amt == 0) {
        // Force a blocking read to avoid infinite loop

            

Reported by PMD.

Avoid reassigning parameters such as 'n'
Design

Line: 311

                 * @throws EOFException if this stream reaches the end before skipping all the bytes
   * @throws IOException if an I/O error occurs, or the stream does not support skipping
   */
  static void skipFully(InputStream in, long n) throws IOException {
    long toSkip = n;
    while (n > 0) {
      long amt = in.skip(n);
      if (amt == 0) {
        // Force a blocking read to avoid infinite loop

            

Reported by PMD.

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

Line: 57

              
/** Tests for {@link NioByteString}. */
@RunWith(JUnit4.class)
public class NioByteStringTest {
  private static final ByteString EMPTY = new NioByteString(ByteBuffer.wrap(new byte[0]));
  private static final String CLASSNAME = NioByteString.class.getSimpleName();
  private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766L);
  private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode();


            

Reported by PMD.

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

Line: 63

                private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766L);
  private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode();

  private final ByteBuffer backingBuffer = ByteBuffer.wrap(BYTES.clone());
  private final ByteString testString = new NioByteString(backingBuffer);

  @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(testString);

            

Reported by PMD.

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

Line: 64

                private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode();

  private final ByteBuffer backingBuffer = ByteBuffer.wrap(BYTES.clone());
  private final ByteString testString = new NioByteString(backingBuffer);

  @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(testString);
    assertWithMessage("%s should match type exactly", CLASSNAME)

            

Reported by PMD.

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

Line: 69

                @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(testString);
    assertWithMessage("%s should match type exactly", CLASSNAME)
        .that(CLASSNAME)
        .isEqualTo(actualClassName);
  }

  protected String getActualClassName(Object object) {

            

Reported by PMD.

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

Line: 69

                @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(testString);
    assertWithMessage("%s should match type exactly", CLASSNAME)
        .that(CLASSNAME)
        .isEqualTo(actualClassName);
  }

  protected String getActualClassName(Object object) {

            

Reported by PMD.

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

Line: 75

                }

  protected String getActualClassName(Object object) {
    String actualClassName = object.getClass().getName();
    actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1);
    return actualClassName;
  }

  @Test

            

Reported by PMD.

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

Line: 76

              
  protected String getActualClassName(Object object) {
    String actualClassName = object.getClass().getName();
    actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1);
    return actualClassName;
  }

  @Test
  public void testByteAt() {

            

Reported by PMD.

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

Line: 76

              
  protected String getActualClassName(Object object) {
    String actualClassName = object.getClass().getName();
    actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1);
    return actualClassName;
  }

  @Test
  public void testByteAt() {

            

Reported by PMD.

java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java
250 issues
This class has too many methods, consider refactoring it.
Design

Line: 47

              
/** Unit test for messages with lazy fields. */
@RunWith(JUnit4.class)
public class LazyMessageLiteTest {

  @Test
  public void testSetValues() {
    LazyNestedInnerMessageLite nested = LazyNestedInnerMessageLite.newBuilder().setNum(3).build();
    LazyInnerMessageLite inner =

            

Reported by PMD.

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

Line: 50

              public class LazyMessageLiteTest {

  @Test
  public void testSetValues() {
    LazyNestedInnerMessageLite nested = LazyNestedInnerMessageLite.newBuilder().setNum(3).build();
    LazyInnerMessageLite inner =
        LazyInnerMessageLite.newBuilder().setNum(2).setNested(nested).build();
    LazyMessageLite outer =
        LazyMessageLite.newBuilder()

            

Reported by PMD.

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

Line: 62

                          .setOneofInner(inner)
            .build();

    assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);


            

Reported by PMD.

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

Line: 62

                          .setOneofInner(inner)
            .build();

    assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);


            

Reported by PMD.

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

Line: 63

                          .build();

    assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);

            

Reported by PMD.

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

Line: 63

                          .build();

    assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);

            

Reported by PMD.

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

Line: 65

                  assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);


            

Reported by PMD.

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

Line: 65

                  assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);


            

Reported by PMD.

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

Line: 65

                  assertThat(outer.getNum()).isEqualTo(1);
    assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);


            

Reported by PMD.

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

Line: 66

                  assertThat(outer.getNumWithDefault()).isEqualTo(421);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNum()).isEqualTo(2);
    assertThat(outer.getInner().getNumWithDefault()).isEqualTo(42);

    assertThat(outer.getInner().getNested().getNum()).isEqualTo(3);

            

Reported by PMD.

python/google/protobuf/internal/generator_test.py
230 issues
No name 'test_bad_identifiers_pb2' in module 'google.protobuf.internal'
Error

Line: 49 Column: 1

              except ImportError:
  import unittest

from google.protobuf.internal import test_bad_identifiers_pb2
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2

            

Reported by Pylint.

No name 'unittest_custom_options_pb2' in module 'google.protobuf'
Error

Line: 50 Column: 1

                import unittest

from google.protobuf.internal import test_bad_identifiers_pb2
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2

            

Reported by Pylint.

No name 'unittest_import_pb2' in module 'google.protobuf'
Error

Line: 51 Column: 1

              
from google.protobuf.internal import test_bad_identifiers_pb2
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2

            

Reported by Pylint.

No name 'unittest_import_public_pb2' in module 'google.protobuf'
Error

Line: 52 Column: 1

              from google.protobuf.internal import test_bad_identifiers_pb2
from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service

            

Reported by Pylint.

No name 'unittest_mset_pb2' in module 'google.protobuf'
Error

Line: 53 Column: 1

              from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service
from google.protobuf import symbol_database

            

Reported by Pylint.

No name 'unittest_mset_wire_format_pb2' in module 'google.protobuf'
Error

Line: 54 Column: 1

              from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service
from google.protobuf import symbol_database


            

Reported by Pylint.

No name 'unittest_no_generic_services_pb2' in module 'google.protobuf'
Error

Line: 55 Column: 1

              from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service
from google.protobuf import symbol_database

MAX_EXTENSION = 536870912

            

Reported by Pylint.

No name 'unittest_pb2' in module 'google.protobuf'
Error

Line: 56 Column: 1

              from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service
from google.protobuf import symbol_database

MAX_EXTENSION = 536870912


            

Reported by Pylint.

TODO(robinson): Flesh this out considerably. We focused on reflection_test.py
Error

Line: 33 Column: 3

              # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# TODO(robinson): Flesh this out considerably.  We focused on reflection_test.py
# first, since it's testing the subtler code, and since it provides decent
# indirect testing of the protocol compiler output.

"""Unittest that directly tests the output of the pure-Python protocol
compiler.  See //google/protobuf/internal/reflection_test.py for a test which

            

Reported by Pylint.

Unused unittest_mset_pb2 imported from google.protobuf
Error

Line: 53 Column: 1

              from google.protobuf import unittest_custom_options_pb2
from google.protobuf import unittest_import_pb2
from google.protobuf import unittest_import_public_pb2
from google.protobuf import unittest_mset_pb2
from google.protobuf import unittest_mset_wire_format_pb2
from google.protobuf import unittest_no_generic_services_pb2
from google.protobuf import unittest_pb2
from google.protobuf import service
from google.protobuf import symbol_database

            

Reported by Pylint.

java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java
227 issues
Avoid reassigning parameters such as 'n'
Design

Line: 292

                 * @throws EOFException if this stream reaches the end before skipping all the bytes
   * @throws IOException if an I/O error occurs, or the stream does not support skipping
   */
  static void skipFully(InputStream in, long n) throws IOException {
    long toSkip = n;
    while (n > 0) {
      long amt = in.skip(n);
      if (amt == 0) {
        // Force a blocking read to avoid infinite loop

            

Reported by PMD.

Avoid reassigning parameters such as 'n'
Design

Line: 292

                 * @throws EOFException if this stream reaches the end before skipping all the bytes
   * @throws IOException if an I/O error occurs, or the stream does not support skipping
   */
  static void skipFully(InputStream in, long n) throws IOException {
    long toSkip = n;
    while (n > 0) {
      long amt = in.skip(n);
      if (amt == 0) {
        // Force a blocking read to avoid infinite loop

            

Reported by PMD.

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

Line: 60

               * BoundedByteString}, see {@link BoundedByteStringTest}.
 */
@RunWith(JUnit4.class)
public class LiteralByteStringTest {
  protected static final String UTF_8 = "UTF-8";

  protected String classUnderTest;
  protected byte[] referenceBytes;
  protected ByteString stringUnderTest;

            

Reported by PMD.

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

Line: 63

              public class LiteralByteStringTest {
  protected static final String UTF_8 = "UTF-8";

  protected String classUnderTest;
  protected byte[] referenceBytes;
  protected ByteString stringUnderTest;
  protected int expectedHashCode;

  @Before

            

Reported by PMD.

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

Line: 64

                protected static final String UTF_8 = "UTF-8";

  protected String classUnderTest;
  protected byte[] referenceBytes;
  protected ByteString stringUnderTest;
  protected int expectedHashCode;

  @Before
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 65

              
  protected String classUnderTest;
  protected byte[] referenceBytes;
  protected ByteString stringUnderTest;
  protected int expectedHashCode;

  @Before
  public void setUp() throws Exception {
    classUnderTest = "LiteralByteString";

            

Reported by PMD.

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

Line: 66

                protected String classUnderTest;
  protected byte[] referenceBytes;
  protected ByteString stringUnderTest;
  protected int expectedHashCode;

  @Before
  public void setUp() throws Exception {
    classUnderTest = "LiteralByteString";
    referenceBytes = ByteStringTest.getTestBytes(1234, 11337766L);

            

Reported by PMD.

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

Line: 79

                @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(stringUnderTest);
    assertWithMessage("%s should match type exactly", classUnderTest)
        .that(classUnderTest)
        .isEqualTo(actualClassName);
  }

  protected String getActualClassName(Object object) {

            

Reported by PMD.

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

Line: 79

                @Test
  public void testExpectedType() {
    String actualClassName = getActualClassName(stringUnderTest);
    assertWithMessage("%s should match type exactly", classUnderTest)
        .that(classUnderTest)
        .isEqualTo(actualClassName);
  }

  protected String getActualClassName(Object object) {

            

Reported by PMD.

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

Line: 85

                }

  protected String getActualClassName(Object object) {
    return object.getClass().getSimpleName();
  }

  @Test
  public void testByteAt() {
    boolean stillEqual = true;

            

Reported by PMD.

java/core/src/main/java/com/google/protobuf/Utf8.java
218 issues
Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 447

                   * (provided by {@code state}) and then finishes validation for the sequence.
     */
    final int partialIsValidUtf8Default(
        final int state, final ByteBuffer buffer, int index, final int limit) {
      if (state != COMPLETE) {
        // The previous decoding operation was incomplete (or malformed).
        // We look for a well-formed sequence consisting of bytes from
        // the previous decoding operation (stored in state) together
        // with bytes from the array slice.

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 540

                   * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
     * than potentially faster approaches.
     */
    private static int partialIsValidUtf8(final ByteBuffer buffer, int index, final int limit) {
      index += estimateConsecutiveAscii(buffer, index, limit);

      for (; ; ) {
        // Optimize for interior runs of ASCII bytes.
        // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 540

                   * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
     * than potentially faster approaches.
     */
    private static int partialIsValidUtf8(final ByteBuffer buffer, int index, final int limit) {
      index += estimateConsecutiveAscii(buffer, index, limit);

      for (; ; ) {
        // Optimize for interior runs of ASCII bytes.
        // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 540

                   * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
     * than potentially faster approaches.
     */
    private static int partialIsValidUtf8(final ByteBuffer buffer, int index, final int limit) {
      index += estimateConsecutiveAscii(buffer, index, limit);

      for (; ; ) {
        // Optimize for interior runs of ASCII bytes.
        // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?

            

Reported by PMD.

Avoid reassigning parameters such as 'index'
Design

Line: 540

                   * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
     * than potentially faster approaches.
     */
    private static int partialIsValidUtf8(final ByteBuffer buffer, int index, final int limit) {
      index += estimateConsecutiveAscii(buffer, index, limit);

      for (; ; ) {
        // Optimize for interior runs of ASCII bytes.
        // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?

            

Reported by PMD.

java/core/src/main/java/com/google/protobuf/ArrayDecoders.java
203 issues
Avoid throwing null pointer exceptions.
Design

Line: 68

              
    Registers(ExtensionRegistryLite extensionRegistry) {
      if (extensionRegistry == null) {
        throw new NullPointerException();
      }
      this.extensionRegistry = extensionRegistry;
    }
  }


            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 78

                 * Decodes a varint. Returns the position after the varint. The decoded varint is stored in
   * registers.int1.
   */
  static int decodeVarint32(byte[] data, int position, Registers registers) {
    int value = data[position++];
    if (value >= 0) {
      registers.int1 = value;
      return position;
    }

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 88

                }

  /** Like decodeVarint32 except that the first byte is already read. */
  static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) {
    int value = firstByte & 0x7F;
    final byte b2 = data[position++];
    if (b2 >= 0) {
      registers.int1 = value | ((int) b2 << 7);
      return position;

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 88

                }

  /** Like decodeVarint32 except that the first byte is already read. */
  static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) {
    int value = firstByte & 0x7F;
    final byte b2 = data[position++];
    if (b2 >= 0) {
      registers.int1 = value | ((int) b2 << 7);
      return position;

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 88

                }

  /** Like decodeVarint32 except that the first byte is already read. */
  static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) {
    int value = firstByte & 0x7F;
    final byte b2 = data[position++];
    if (b2 >= 0) {
      registers.int1 = value | ((int) b2 << 7);
      return position;

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 88

                }

  /** Like decodeVarint32 except that the first byte is already read. */
  static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) {
    int value = firstByte & 0x7F;
    final byte b2 = data[position++];
    if (b2 >= 0) {
      registers.int1 = value | ((int) b2 << 7);
      return position;

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 88

                }

  /** Like decodeVarint32 except that the first byte is already read. */
  static int decodeVarint32(int firstByte, byte[] data, int position, Registers registers) {
    int value = firstByte & 0x7F;
    final byte b2 = data[position++];
    if (b2 >= 0) {
      registers.int1 = value | ((int) b2 << 7);
      return position;

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 128

                 * Decodes a varint. Returns the position after the varint. The decoded varint is stored in
   * registers.long1.
   */
  static int decodeVarint64(byte[] data, int position, Registers registers) {
    long value = data[position++];
    if (value >= 0) {
      registers.long1 = value;
      return position;
    } else {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 139

                }

  /** Like decodeVarint64 except that the first byte is already read. */
  static int decodeVarint64(long firstByte, byte[] data, int position, Registers registers) {
    long value = firstByte & 0x7F;
    byte next = data[position++];
    int shift = 7;
    value |= (long) (next & 0x7F) << 7;
    while (next < 0) {

            

Reported by PMD.

Avoid reassigning parameters such as 'position'
Design

Line: 139

                }

  /** Like decodeVarint64 except that the first byte is already read. */
  static int decodeVarint64(long firstByte, byte[] data, int position, Registers registers) {
    long value = firstByte & 0x7F;
    byte next = data[position++];
    int shift = 7;
    value |= (long) (next & 0x7F) << 7;
    while (next < 0) {

            

Reported by PMD.

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

Line: 50

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SmallSortedMapTest {
  // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
  // here for JDK 1.5 users.
  private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

            

Reported by PMD.

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

Line: 50

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SmallSortedMapTest {
  // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
  // here for JDK 1.5 users.
  private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

            

Reported by PMD.

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

Line: 50

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SmallSortedMapTest {
  // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
  // here for JDK 1.5 users.
  private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

            

Reported by PMD.

Possible God Class (WMC=54, ATFD=35, TCC=0.000%)
Design

Line: 50

              import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class SmallSortedMapTest {
  // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
  // here for JDK 1.5 users.
  private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
    private final K key;
    private V value;

            

Reported by PMD.

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

Line: 89

                      return false;
      }
      Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
      return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    @Override
    public int hashCode() {
      return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());

            

Reported by PMD.

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

Line: 89

                      return false;
      }
      Map.Entry<?, ?> e = (Map.Entry<?, ?>) o;
      return eq(key, e.getKey()) && eq(value, e.getValue());
    }

    @Override
    public int hashCode() {
      return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode());

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 99

                }

  @Test
  public void testPutAndGetArrayEntriesOnly() {
    runPutAndGetTest(3);
  }

  @Test
  public void testPutAndGetOverflowEntries() {

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 104

                }

  @Test
  public void testPutAndGetOverflowEntries() {
    runPutAndGetTest(6);
  }

  private void runPutAndGetTest(int numElements) {
    // Test with even and odd arraySize

            

Reported by PMD.

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

Line: 117

              
    // Test with puts in ascending order.
    for (int i = 0; i < numElements; i++) {
      assertThat(map1.put(i, i + 1)).isNull();
      assertThat(map2.put(i, i + 1)).isNull();
    }
    // Test with puts in descending order.
    for (int i = numElements - 1; i >= 0; i--) {
      assertThat(map3.put(i, i + 1)).isNull();

            

Reported by PMD.

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

Line: 118

                  // Test with puts in ascending order.
    for (int i = 0; i < numElements; i++) {
      assertThat(map1.put(i, i + 1)).isNull();
      assertThat(map2.put(i, i + 1)).isNull();
    }
    // Test with puts in descending order.
    for (int i = numElements - 1; i >= 0; i--) {
      assertThat(map3.put(i, i + 1)).isNull();
      assertThat(map4.put(i, i + 1)).isNull();

            

Reported by PMD.