private synchronized void internalCheckConsistency(IProgressMonitor monitor)
     throws OperationCanceledException {
   // Setting fNeedsConsistencyCheck is necessary here since
   // markAsInconsistent isn't synchronized.
   fNeedsConsistencyCheck = true;
   List typesToCheck = new ArrayList(getKeys());
   monitor.beginTask(CorextMessages.TypeInfoHistory_consistency_check, typesToCheck.size());
   monitor.setTaskName(CorextMessages.TypeInfoHistory_consistency_check);
   for (Iterator iter = typesToCheck.iterator(); iter.hasNext(); ) {
     TypeNameMatch type = (TypeNameMatch) iter.next();
     long currentTimestamp = getContainerTimestamp(type);
     Long lastTested = (Long) fTimestampMapping.get(type);
     if (lastTested != null
         && currentTimestamp != IResource.NULL_STAMP
         && currentTimestamp == lastTested.longValue()
         && !isContainerDirty(type)) continue;
     try {
       IType jType = type.getType();
       if (jType == null || !jType.exists()) {
         remove(type);
       } else {
         // copy over the modifiers since they may have changed
         int modifiers = jType.getFlags();
         if (modifiers != type.getModifiers()) {
           replace(type, SearchEngine.createTypeNameMatch(jType, modifiers));
         } else {
           fTimestampMapping.put(type, new Long(currentTimestamp));
         }
       }
     } catch (JavaModelException e) {
       remove(type);
     }
     if (monitor.isCanceled()) throw new OperationCanceledException();
     monitor.worked(1);
   }
   monitor.done();
   fNeedsConsistencyCheck = false;
 }