Skip to content

Null value for number_missing_values #20

Open

Description

@ArlindKadra

When using the data features, while passing through each feature, I found a null value for number_missing_values. The following code can replicate the problem:

OpenmlConnector connector = new OpenmlConnector("https://www.openml.org/", "9ed41f60b87fbe17054397936b96212d");
		Settings.CACHE_ALLOWED = false;
		DataFeature dataFeatures = connector.dataFeatures(2);
		for(Feature feature : dataFeatures.getFeatures()) {
			if(feature.getNumberOfMissingValues() != null && feature.getNumberOfMissingValues() instanceof Integer) {
				continue;
			} else {
				throw new IllegalArgumentException();
			}
		}

Activity

  1. rohansen856 commented on Nov 16, 2025

    @rohansen856

    Hi @ArlindKadra the getNumberOfMissingValues() could return null when the OpenML API returns empty XML elements like <oml:NumberOfMissingValues />. The problem occurred because: XStream XML parsing library had no converter for empty Integer elements, only for empty Double elements via EmptyDoubleConverter

    I propose a fix with the following solution:

    1. Create EmptyIntegerConverter.java in apiconnector/src/main/java/org/openml/apiconnector/xstream:
      package org.openml.apiconnector.xstream;
    
      import org.apache.commons.lang3.StringUtils;
      import com.thoughtworks.xstream.converters.basic.IntConverter;
    
      public class EmptyIntegerConverter extends IntConverter {
          public boolean canConvert(Class type) {
              return type.equals(Integer.class);
          }
    
          public Object fromString(String str) {
              if (StringUtils.isEmpty(str)) {
                  return null;
              }
              return Integer.valueOf(str);
          }
      }
    1. Modify: XstreamXmlMapping.java (line 105-106):
      xstream.registerConverter(new EmptyDoubleConverter());
      xstream.registerConverter(new EmptyIntegerConverter()); // Added this line

    These changes ensure that:

    • When the API returns <oml:NumberOfMissingValues />, XStream now properly converts it to null instead of causing a parsing exception
    • The user's code that checks feature.getNumberOfMissingValues() != null && feature.getNumberOfMissingValues() instanceof Integer now works correctly
    • Empty XML elements for any Integer field in DataFeature are now handled gracefully

    The fix ensures backward compatibility while resolving the null pointer issue.

    I would like to raise a PR with the approach to solve this issue. Thannks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions