Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-14385

Fix Some Potential NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Incomplete
    • None
    • None
    • Normal

    Description

      We have developed a static analysis tool NPEDetector to find some potential NPE. Our analysis shows that some callees may return null in corner case(e.g. node crash , IO exception), some of their callers have  !=null check but some do not have. In this issue we post a patch which can add  !=null  based on existed !=null  check. For example:

      Calle Schema#getView may return null:

      public ViewMetadata getView(String keyspaceName, String viewName)
      {
          assert keyspaceName != null;
          KeyspaceMetadata ksm = keyspaces.getNullable(keyspaceName);
          return (ksm == null) ? null : ksm.views.getNullable(viewName);//may return null
      }
      

       it have 4 callers, 3 of them have !=null check, like its caller MigrationManager#announceViewDrop have !=null check()

      public static void announceViewDrop(String ksName, String viewName, boolean announceLocally) throws ConfigurationException
      {
         ViewMetadata view = Schema.instance.getView(ksName, viewName);
          if (view == null)//null pointer checker
              throw new ConfigurationException(String.format("Cannot drop non existing materialized view '%s' in keyspace '%s'.", viewName,     ksName));
         KeyspaceMetadata ksm = Schema.instance.getKeyspaceMetadata(ksName);
      
         logger.info("Drop table '{}/{}'", view.keyspace, view.name);
         announce(SchemaKeyspace.makeDropViewMutation(ksm, view, FBUtilities.timestampMicros()), announceLocally);
      }
      

      but caller MigrationManager#announceMigration does not have 

      We add !=null check based on MigrationManager#announceViewDrop:

      if (current == null)
          throw new InvalidRequestException("There is no materialized view in keyspace " + keyspace());
      

      But due to we are not very  familiar with CASSANDRA, hope some expert can review it.

      Thanks!!!!

       

      Attachments

        1. CA-14385_1.patch
          2 kB
          lujie

        Issue Links

          Activity

            People

              Unassigned Unassigned
              xiaoheipangzi lujie
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h