Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-5004

Warning in GenericEntity.get unnecessarily clutters logs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Trunk
    • 14.12.01
    • framework
    • None

    Description

      This code in GenericEntity.java:

      Debug.logWarning("The field name (or key) [" + name + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
      

      is really annoying and IMHO it is wrong.

      First, it does not print an exception, it only prints that string with no stacktrace (I think that was changed at some point).

      Second, IllegalArgument is a RuntimeException so the interface doesn't really need to allow it to be thrown, right?

      Personally, I think the warning is not even justified. We sometimes don't know exactly what kind of entity we're dealing with and just check if it has that field or not. With this code, to prevent excessive log clutter, we have to wrap each call with a "if (it.containsKey())". A java map will just return null silently as well, and this behavior is documented in the Map interface. If anyone is really worried about accessing fields wrong (your tests should catch that error), there could be an extra method "getOrThrow" or something, but get should just return the value or null.

      Otherwise, at least throw the exception. Log warnings are usually found while monitoring production logs, developers will find this much earlier otherwise.

      Attachments

        1. iae.patch
          2 kB
          Jacopo Cappellato

        Issue Links

          Activity

            People

              jacopoc Jacopo Cappellato
              c089 Christoph Neuroth
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: