lib/spotbugs/entity/bug_instance.rb in danger-spotbugs-0.0.3 vs lib/spotbugs/entity/bug_instance.rb in danger-spotbugs-0.0.4

- old
+ new

@@ -24,21 +24,21 @@ def type @type ||= rank > RANK_ERROR_THRESHOLD ? :warn : :fail end def line - @line ||= bug_instance.xpath('SourceLine').attribute('start').compact.first.value.to_i + @line ||= get_value_safely(bug_instance.xpath('SourceLine').attribute('start'), 0).to_i end def description @description ||= bug_instance.xpath('LongMessage').text end private def get_source_path(bug_instance) - bug_instance.xpath('SourceLine').attribute('sourcepath').compact.first.value.to_s + get_value_safely(bug_instance.xpath('SourceLine').attribute('sourcepath'), '').to_s end def get_absolute_path(source_path) @source_dirs.map do |source_dir| return source_dir if source_dir.end_with?(source_path) @@ -53,7 +53,11 @@ end end def file_separator File::ALT_SEPARATOR || File::SEPARATOR + end + + def get_value_safely(array, default_value) + array.compact.empty? ? default_value : array.compact.first.value end end