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.patch
        0.7 kB
        Bruno P. Kinoshita
      2. FUNCTOR-8-tests.patch
        6 kB
        Bruno P. Kinoshita

        Activity

          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