commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita (Created) (JIRA)" <j...@apache.org>
Subject [jira] [Created] (FUNCTOR-8) [PATCH] Possible NPE in TransformedGenerator if getWrappedGenerator() is overridden to return null
Date Tue, 01 Nov 2011 03:14:32 GMT
[PATCH] Possible NPE in TransformedGenerator if getWrappedGenerator() is overridden to return
null
--------------------------------------------------------------------------------------------------

                 Key: FUNCTOR-8
                 URL: https://issues.apache.org/jira/browse/FUNCTOR-8
             Project: Commons Functor
          Issue Type: Bug
         Environment: ubuntu 11.10, sun-jdk-6, eclipse galileo
            Reporter: Bruno P. Kinoshita
         Attachments: FUNCTOR-8.patch

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

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message