Changeset 16542

Show
Ignore:
Timestamp:
20/08/08 11:10:51 (4 months ago)
Author:
kmr
Message:

Fix for NullPointerException? when removing a node from a PathQuery? with errors.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/intermine/web/main/src/org/intermine/web/struts/QueryBuilderChange.java

    r15966 r16542  
    150150            } 
    151151            String pathLastField = path.substring(path.lastIndexOf(".") + 1); 
    152             FieldDescriptor fd = parentCld.getFieldDescriptorByName(pathLastField); 
    153  
    154             if (fd instanceof ReferenceDescriptor) { 
    155                 ReferenceDescriptor rf = (ReferenceDescriptor) fd; 
    156                 ClassDescriptor realClassDescriptor = rf.getReferencedClassDescriptor(); 
    157  
    158                 Iterator<Path> viewPathIter = pathQuery.getView().iterator(); 
    159  
    160                 while (viewPathIter.hasNext()) { 
    161                     String viewPath = viewPathIter.next().toStringNoConstraints(); 
    162  
    163                     if (viewPath.startsWith(path) && !viewPath.equals(path)) { 
    164                         String fieldName = viewPath.substring(path.length() + 1); 
    165  
    166                         if (fieldName.indexOf(".") != -1) { 
    167                             fieldName = fieldName.substring(0, fieldName.indexOf(".")); 
    168                         } 
    169  
    170                         if (realClassDescriptor.getFieldDescriptorByName(fieldName) == null) { 
    171                             // the field must be in a sub-class rather than the base class so remove 
    172                             // the viewPath 
    173                             viewPathIter.remove(); 
    174                         } 
    175                     } 
    176                 } 
    177                 if (pathQuery.getSortOrder() != null) { 
    178                     Iterator<OrderBy> sortOrderPathIter = pathQuery.getSortOrder().iterator(); 
    179  
    180                     while (sortOrderPathIter.hasNext()) { 
    181                         String sortOrderPath 
    182                         = sortOrderPathIter.next().getField().toStringNoConstraints(); 
    183  
    184                         if (sortOrderPath.startsWith(path) && !sortOrderPath.equals(path)) { 
    185                             String fieldName = sortOrderPath.substring(path.length() + 1); 
     152            if (parentCld == null) { 
     153                // if the field doesn't exist it means we are editing a PathQuery with errors 
     154            } else { 
     155                FieldDescriptor fd = parentCld.getFieldDescriptorByName(pathLastField); 
     156 
     157                if (fd instanceof ReferenceDescriptor) { 
     158                    ReferenceDescriptor rf = (ReferenceDescriptor) fd; 
     159                    ClassDescriptor realClassDescriptor = rf.getReferencedClassDescriptor(); 
     160 
     161                    Iterator<Path> viewPathIter = pathQuery.getView().iterator(); 
     162 
     163                    while (viewPathIter.hasNext()) { 
     164                        String viewPath = viewPathIter.next().toStringNoConstraints(); 
     165 
     166                        if (viewPath.startsWith(path) && !viewPath.equals(path)) { 
     167                            String fieldName = viewPath.substring(path.length() + 1); 
    186168 
    187169                            if (fieldName.indexOf(".") != -1) { 
     
    190172 
    191173                            if (realClassDescriptor.getFieldDescriptorByName(fieldName) == null) { 
    192                                 // the field must be in a sub-class rather than the base class 
    193                                 // so remove the sortPath 
    194                                 sortOrderPathIter.remove(); 
     174                                // the field must be in a sub-class rather than the base class so 
     175                                // remove the viewPath 
     176                                viewPathIter.remove(); 
     177                            } 
     178                        } 
     179                    } 
     180                    if (pathQuery.getSortOrder() != null) { 
     181                        Iterator<OrderBy> sortOrderPathIter = pathQuery.getSortOrder().iterator(); 
     182 
     183                        while (sortOrderPathIter.hasNext()) { 
     184                            String sortOrderPath 
     185                            = sortOrderPathIter.next().getField().toStringNoConstraints(); 
     186 
     187                            if (sortOrderPath.startsWith(path) && !sortOrderPath.equals(path)) { 
     188                                String fieldName = sortOrderPath.substring(path.length() + 1); 
     189 
     190                                if (fieldName.indexOf(".") != -1) { 
     191                                    fieldName = fieldName.substring(0, fieldName.indexOf(".")); 
     192                                } 
     193 
     194                                FieldDescriptor fieldDescriptor = 
     195                                    realClassDescriptor.getFieldDescriptorByName(fieldName); 
     196                                if (fieldDescriptor == null) { 
     197                                    // the field must be in a sub-class rather than the base class 
     198                                    // so remove the sortPath 
     199                                    sortOrderPathIter.remove(); 
     200                                } 
    195201                            } 
    196202                        }