Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-798

@RooToString doesn't handle nulls correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.2.RELEASE
    • Fix Version/s: 1.1.0.M1
    • Component/s: GENERAL OBJECTS
    • Labels:
      None

      Description

      Given an entity like this:

      @Entity
      @RooJavaBean
      @RooToString
      @RooEntity
      public class HistoricalItem {

      @NotNull
      @Size(min = 1)
      private String title;

      @Temporal(TemporalType.TIMESTAMP)
      @DateTimeFormat(style = "MM", iso = ISO.DATE_TIME)
      private Calendar lastUpdated;

      @OneToMany(cascade = CascadeType.ALL, mappedBy = "historicalItem")
      private Set<HistoricalPrice> historicalPrices = new HashSet<HistoricalPrice>();

      @PrePersist
      protected void onCreate()

      { dateCreated = new GregorianCalendar(); lastUpdated = new GregorianCalendar(); }

      @PreUpdate
      protected void onUpdate()

      { lastUpdated = new GregorianCalendar(); }

      }

      Roo generates a ToString like this:

      public String HistoricalItem.toString() {
      StringBuilder sb = new StringBuilder();
      sb.append("Id: ").append(getId()).append(", ");
      sb.append("Version: ").append(getVersion()).append(", ");
      sb.append("Title: ").append(getTitle()).append(", ");
      sb.append("DateCreated: ").append(getDateCreated().getTime()).append(", "); // Throws NPE !!!
      sb.append("LastUpdated: ").append(getLastUpdated().getTime()).append(", "); // Throws NPE !!!
      return sb.toString();
      }

      I need dateCreated and lastUpdated to be null when creating the entity so initializing them is not an option.

      Roo needs to add the necessary null checks before attempting to call Calendar.getTime()

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              balex Ben Alex
              Reporter:
              eliseosoto Eliseo Soto
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: