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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.0
    • None
    • 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-tests.patch
          6 kB
          Bruno P. Kinoshita
        2. FUNCTOR-8.patch
          0.7 kB
          Bruno P. Kinoshita

        Activity

          People

            simone.tripodi Simone Tripodi
            kinow Bruno P. Kinoshita
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: