Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-4421

Null Pointer Exception can occur when bitstream.bitstream_format_id is null

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Received (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 7.0
    • Fix Version/s: None
    • Component/s: REST API v7
    • Labels:
      None
    • Environment:
      RHEL 7.7; Apache Tomcat 9.0.14; OpenJDK 1.8.0_232; PostgreSQL 11.1
    • Attachments:
      0
    • Comments:
      1
    • Documentation Status:
      Needed

      Description

      When bitstream.bitstream_format_id is null in the database, a null pointer exception can occur, for instance with the endpoint /server/api/core/communities/search/top?page=0&size=5&sort=dc.title,ASC (which is called by the home page of the angular client).  In this case a community logo has a bitstream_format_id = null.  This results in a series of method calls like so (comments are mine to indicate the problem):

      BitstreamConverter.java#L52
      convert() calls obj.getFormat(null); // null is hard-coded
      Bitstream.java#L267
      getFormat() calls getBitstreamService().getFormat(context [=null], ...); // context is still null
      BitstreamServiceImpl.java#L416
      getFormat() calls bitstreamFormatService.findUnknown(context [=null]); // context is still null
      BitstreamFormatServiceImpl.java#L100
      findUnknown() calls findByShortDescription(context [=null], ...); // context is still null
      BitstreamFormatServiceImpl#L95
      findByShortDescription() calls bitstreamFormatDAO.findByShortDescription(context [=null], ...); // context is still null
      (this call occurs because bitstream.getBitstreamFormat() returns null for a couple dozen of my bitstreams)
      BitstreamFormatDAOImpl.java#L84
      findByShortDescription() calls getCriteriaBuilder(context [=null]); // context is still null
      AbstractHibernateDAO.java#L371
      getCriteriaBuilder() calls getHIbernateSession(context [=null]); // context is still null
      AbstractHibernateDAO#L59
      getHibernateSession() calls getDBConnection(); on the null context object which throws the NPE

      Note that context is hard coded as null in BitstreamConverter, and remains uninitialized and null until getHIbernateSession() when the uncaught exception is thrown.

       

      There may be other rest endpoints that are affected, this one is most apparent because it impacts the home page.

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            tantz001 Bill Tantzen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: