Uploaded image for project: 'Commons Functor'
  1. Commons Functor
  2. FUNCTOR-8

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: 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

        Attachments

        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 Simone Tripodi
              Reporter:
              kinow Bruno P. Kinoshita
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: