Uploaded image for project: 'Sqoop'
  1. Sqoop
  2. SQOOP-2006

bad smell: NPE check in SQOOP-1995 is not obvious

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.99.5
    • Fix Version/s: 1.99.5
    • Component/s: None
    • Labels:
      None

      Description

      SQOOP-1995 fixed a NPE, which is adding a schema NPE check in 6 get/set FooData methods. Veena Basavaraj explained that the IDF class can be instantiated by reflection, which will call the default no arg constructor, so that the property schema will not be assigned expectedly.

      IMO, although the patch can guard invalid access to a null schema, but as the getter and setter methods have nothing to do with schema and there is no comment left, it will be hard to understand why we have such code after couple of months.

      It seems a IDF class should have a not null schema the whole life time. I've some options:
      1. We check null schema where a NPE happens
      2. Disallow reflection of IDF class or search all code occurrences to make sure schema will be set properly (I think we already have test cases to guard use cases)
      3. Use some design by contract framework (https://github.com/nhatminhle/cofoja) to define invariant, e.g. @Invariant(schema != null).

        Attachments

        1. SQOOP-2006.patch
          9 kB
          Qian Xu

          Issue Links

            Activity

              People

              • Assignee:
                stanleyxu2005 Qian Xu
                Reporter:
                stanleyxu2005 Qian Xu
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: