Commons Functor
  1. Commons Functor
  2. FUNCTOR-8

[PATCH] Possible NPE in TransformedGenerator if getWrappedGenerator() is overridden to return null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Labels:
      None
    • Environment:

      ubuntu 11.10, sun-jdk-6, eclipse galileo

      Description

      If we override getWrappedGenerator method in TransformedGenerator to return null, it may result in a NullPointerException if hashCode is called.

      Attached the patch for it, and below a snippet of code to reproduce this issue.

      TransformedGenerator<Integer, Integer> t = new TransformedGenerator<Integer, Integer>(
      new IntegerRange(1, 10), new UnaryFunction<Integer, Integer>() {
      public Integer evaluate(Integer obj)

      { return obj += 1; }

      }) {
      @Override
      protected Generator<? extends Integer> getWrappedGenerator()

      { return null; }

      };

      TransformedGenerator<Integer, Integer> t2 = new TransformedGenerator<Integer, Integer>(
      new IntegerRange(1, 10), new UnaryFunction<Integer, Integer>() {
      public Integer evaluate(Integer obj)

      { return obj -= 1; }

      });

      System.out.println(t.equals(t2));

      System.out.println(t.hashCode() == t2.hashCode()); // NPE

      Cheers,
      Bruno P. Kinoshita

      1. FUNCTOR-8-tests.patch
        6 kB
        Bruno P. Kinoshita
      2. FUNCTOR-8.patch
        0.7 kB
        Bruno P. Kinoshita

        Activity

        Hide
        Bruno P. Kinoshita added a comment -

        A fix for the NPE in TransformedGenerator.

        Show
        Bruno P. Kinoshita added a comment - A fix for the NPE in TransformedGenerator.
        Hide
        Bruno P. Kinoshita added a comment -

        FUNCTOR-8-tests.patch includes a unit test for FUNCTOR-8.patch.

        I attached a separated file for part of this class is also contained in FUNCTOR-7.patch, so it may help while committing it if FUNCTOR-7 has already been applied.

        Show
        Bruno P. Kinoshita added a comment - FUNCTOR-8 -tests.patch includes a unit test for FUNCTOR-8 .patch. I attached a separated file for part of this class is also contained in FUNCTOR-7 .patch, so it may help while committing it if FUNCTOR-7 has already been applied.
        Hide
        Simone Tripodi added a comment -

        patch applied, see r1344780

        thanks once again for contributing, Bruno!

        Show
        Simone Tripodi added a comment - patch applied, see r1344780 thanks once again for contributing, Bruno!

          People

          • Assignee:
            Simone Tripodi
            Reporter:
            Bruno P. Kinoshita
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development