Opened 17 years ago

Closed 17 years ago

#915 closed defect (fixed)

NullPointerException when a raw data type is missing

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: major Milestone: BASE 2.6
Component: core Version:
Keywords: Cc:

Description (last modified by Nicklas Nordborg)

If a raw data type is removed from the raw-data-types.xml file and there are raw bioassays in the database that uses the removed raw data type, the call to RawBioassay.getRawDataType() will return null. This causes a lot of trouble for many parts of the code since null is not an allowed return value. I think the Experiment.getRawDataType() may be affected by the same problem.

Since the configuration is in an external file there are no database constraints that we can lean on to make sure that used raw data types are never deleted. Maybe we can have a "dummy" raw data type so we don't have to return null.

Example stacktrace:

java.lang.NullPointerException
   at org.apache.jsp.views.rawbioassays.list_005frawbioassays_jsp._jspService(list_005frawbioassays_jsp.java:1295)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

Line 1295 in list_rawbioassays.jsp is:

out.print(HTML.encodeTags(rdt.getName()));

Change History (3)

comment:1 by Nicklas Nordborg, 17 years ago

Description: modified (diff)

comment:2 by Nicklas Nordborg, 17 years ago

Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

Hmmm.... I have checked the code and the RawDataType is used in a LOT of places. I don't think returning a "dummy" object would be of any help. It would just delay the exception until later and would probably confuse things even more. Instead, I think it is better to modify the RawDataTypes.getRawDataType() method to throw an exception if the raw data type is missing. This introduces a backwards compatibility problem for client code that have actually followed the documentation and checked if the return value is null or not.

Hmmm... maybe it is better to instead add a RawDataTypes.getSafeRawDataType() that throws an exception. It will not affect other client code, and we can easily change our own code to use the new method instead.

comment:3 by Nicklas Nordborg, 17 years ago

Resolution: fixed
Status: assignedclosed

(In [4124]) Fixes #915: NullPointerException when a raw data type is missing

Use RawDataTypes.getSafeRawDataType() instead, which throws an exception immediately.

Note: See TracTickets for help on using tickets.