Bugs: Browse | Submit New | Admin

[#16403] Gruff fails in base.rb when nil value passed into method larger_than_max?

Date:
2007-12-18 05:12
Priority:
3
Submitted By:
Rich Bloch (richbl)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Gruff fails in base.rb when nil value passed into method larger_than_max?

Detailed description
Does:

In Gruff (0.2.9), when a nil value for @maximum_value is passed in, Rails will generate the following error:

comparison of Fixnum with nil failed

at
/var/lib/gems/1.8/gems/gruff-0.2.9/lib/gruff/base.rb:901:in `larger_than_max?'

A trace shows the larger_than_max? method does no checking for nil of method variable @maximum_value prior to a fixnum
operator compare (in this case, > or greater_than):

    # Overridden by subclasses such as stacked bar.
    def larger_than_max?(data_point, index=0) # :nodoc:
      data_point > @maximum_value
    end

Should:

Checking for a nil condition on the method variable will resolve the problem:

    # Overridden by subclasses such as stacked bar.
    def larger_than_max?(data_point, index=0) # :nodoc:
      data_point > (@maximum_value.nil? ? 0 : @maximum_value)
    end

However, given the comment for this method, I suspect that other classes (e.g. stacked bar) may exhibit the same failure
case.

Also of note: the method just below larger_than_max? is less_than_min? and no check for nil is made there either. So,
I suspect that this same error case may exist, though I have not exercised this condition.

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item