Opened 5 years ago

Closed 5 years ago

#1992 closed defect (fixed)

The BASE core API allows annotations to be created without values

Reported by: Nicklas Nordborg Owned by: everyone
Priority: minor Milestone: BASE 3.8
Component: core Version:
Keywords: Cc:

Description (last modified by Nicklas Nordborg)

This is something that is not possible to reproduce with the web client since if no values has been specified it will never try to create any annotations. However, the BASE core API allows an annotation to be created but never checks that values have been set for it.

On the other hand, trying to set an existing annotation to null will throw an exception (as expected).

The code for creating the empty annotations go something like this (assuming that we have an annotatable item and an annotation type):

Annotatable item = ...
AnnotationType at = ...
AnnotationSet as = item.getAnnotationSet();
Annotation a = as.getAnnotation(at); // <-The empty annotation is created here

// a.setValue(aValue) must be called to create a non-empty annotation

dc.commit(); // <- We must check that annotation values has been set here

The annotation information is spread out over multiple database tables. If the Annotation.setValue() method is called to set the annotation, here is what happens:

  • An entry in the Annotations table is created
  • An entry in the ParameterValues table is created
  • An entry in the actual data table is created. The actual table depends on the data type. For example StringValues for string annotations or IntegerValues for integer annotations.

If the Annotation.setValue() method is not called only the first two entries are created but not the third. This can result in some strange behavior in other places since if an annotation entry exists it is expected to have at least one value.

Change History (5)

comment:1 Changed 5 years ago by Nicklas Nordborg

Description: modified (diff)

comment:2 Changed 5 years ago by Nicklas Nordborg

(In [7106]) References #1992: The BASE core API allows annotations to be created without values

Added test code for testing this use case.

comment:3 Changed 5 years ago by Nicklas Nordborg

This issue is somewhat similar to #1717 but the situation in #1717 can occur during normal operation. The issue described in this ticket should be considered as an error.

comment:4 Changed 5 years ago by Nicklas Nordborg

(In [7107]) References #1992: The BASE core API allows annotations to be created without values

Added schema update script for fixing (=deleting) annotations that have no values.

comment:5 Changed 5 years ago by Nicklas Nordborg

Resolution: fixed
Status: newclosed

(In [7109]) Fixes #1992: The BASE core API allows annotations to be created without values

Added checking in the Annotation class to make sure that no annotations are created without values and that trying to set the value to an empty list is throwing an exception.

Note: See TracTickets for help on using tickets.