Opened 6 months ago

Last modified 4 weeks ago

#2723 reviewing defect

Providing variable values as double[] to Dataset fails at runtime

Reported by: abeham Owned by: gkronber
Priority: medium Milestone: HeuristicLab 3.3.15
Component: Problems.DataAnalysis Version: 3.3.14
Keywords: Cc:


In the Dataset class an IList is accepted as variable values, however later on this IList is cast as a List<T>.

public Dataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues)
  : base() {

  // line 199:
  List<T> values = list as List<T>;
  if (values == null) throw new ArgumentException("The variable " + variableName + " is not a " + typeof(T) + " variable.");

Now, a double[] is an IList, but not a List<double>. The compiler is happy, but the program crashes at runtime. In my opinion, it should be checked if it's a T[] in case List<T> fails or otherwise prevent accepting double[] in the constructor.

Change History (6)

comment:1 Changed 2 months ago by bburlacu

r14857: Add DatasetUtil static class with useful methods for dealing with Datasets. Add input validation to Dataset constructor.

comment:2 Changed 4 weeks ago by gkronber

  • Owner set to bburlacu
  • Status changed from new to assigned

I think r14857 is not related to the ticket description.

comment:3 Changed 4 weeks ago by bburlacu

  • Owner changed from bburlacu to gkronber
  • Status changed from assigned to reviewing

comment:4 Changed 4 weeks ago by abeham

I agree with gkronber, this change does not adress the ticket.

comment:5 Changed 4 weeks ago by bburlacu

r15013: Found a different solution to this issue, by using IList<T> as the return type for the GetValues<T> method.

comment:6 Changed 4 weeks ago by bburlacu

r15015: Fix exception in Dataset.cs when calling the ToModifiable() method.

Note: See TracTickets for help on using tickets.