#vulnerable code 
                             @SuppressWarnings("rawtypes")
	@Override
	public void onFinished(Invocation invocation,Object result) {
		Object[] args = invocation.getArgs();
		MappedStatement mt = (MappedStatement)args[0]; 
		
		String mapperNameSpace = mt.getId().substring(0, mt.getId().lastIndexOf(SPLIT_PONIT));
		
		QueryMethodCache cacheInfo = null;
		if(mt.getSqlCommandType().equals(SqlCommandType.SELECT)){	
			if(result == null)return;  
			if((cacheInfo = getQueryMethodCache(mt.getId())) == null)return;
			
			if(result instanceof List){
				List list = (List)result;
				if(list.isEmpty())return;
				result = cacheInfo.collectionResult ? result : list.get(0);
			}
			final String cacheKey = genarateQueryCacheKey(cacheInfo.keyPattern, args[1]);
			//按主键查询以及标记非引用关系的缓存直接读取缓存
			if(cacheInfo.isSecondQueryById() == false){
				if(cacheProvider.set(cacheKey,result, cacheInfo.expire)){
					if(logger.isDebugEnabled())logger.debug("method[{}] put result to cache，cacheKey:{}",mt.getId(),cacheKey);
				}
				//结果为集合的情况，增加key到cacheGroup
				if(cacheInfo.groupRalated){
					cacheProvider.putGroupKeys(cacheInfo.cacheGroupKey, cacheKey,cacheInfo.expire);
					logger.debug("method[{}] add key:[{}] to group key:[{}]",mt.getId(),cacheInfo.cacheGroupKey, cacheKey);
				}else{
					//
					cacheUniqueSelectRef(result, mt, cacheKey);
				}
			}else{
				//之前没有按主键的缓存，增加按主键缓存
				String idCacheKey = genarateQueryCacheKey(getQueryByPkMethodCache(mt.getId()).keyPattern,result);
				
				if(idCacheKey != null && cacheKey != null && cacheProvider.set(idCacheKey,result, cacheInfo.expire) 
						&& cacheProvider.set(cacheKey,idCacheKey, cacheInfo.expire)){
					if(logger.isDebugEnabled())logger.debug("method[{}] put result to cache，cacheKey:{},and add ref cacheKey:{}",mt.getId(),idCacheKey,cacheKey);
				}
			}
		}else{
			//返回0，未更新成功
			if(result != null && ((int)result) == 0)return;
			
			if(updateCacheMethods.containsKey(mt.getId())){
				String cacheByPkKey = null;
				UpdateByPkMethodCache updateMethodCache = updateCacheMethods.get(mt.getId());
				if(updateMethodCache.sqlCommandType.equals(SqlCommandType.DELETE)){
					cacheByPkKey = genarateQueryCacheKey(updateMethodCache.keyPattern,args[1]);
					cacheProvider.remove(cacheByPkKey);
					if(logger.isDebugEnabled())logger.debug("method[{}] remove cacheKey:{} from cache",mt.getId(),cacheByPkKey);
				}else{
					cacheByPkKey = genarateQueryCacheKey(updateMethodCache.keyPattern,args[1]);
					boolean insertCommond = mt.getSqlCommandType().equals(SqlCommandType.INSERT);
					if(insertCommond || mt.getSqlCommandType().equals(SqlCommandType.UPDATE)){
						if(result != null){
							QueryMethodCache queryByPkMethodCache = getQueryByPkMethodCache(mt.getId());
							cacheProvider.set(cacheByPkKey,args[1], queryByPkMethodCache.expire);
							if(logger.isDebugEnabled())logger.debug("method[{}] update cacheKey:{}",mt.getId(),cacheByPkKey);
							//插入其他唯一字段引用
							if(insertCommond)cacheUniqueSelectRef(args[1], mt, cacheByPkKey);
							//
							addCurrentThreadCacheKey(cacheByPkKey);
						}
					}
				}				
			}else{//按条件删除和更新的情况
				System.out.println(args);
				System.out.println(mt);
				BoundSql boundSql = mt.getBoundSql(args[1]);
				
				Object parameterObject2 = boundSql.getParameterObject();
				System.out.println(parameterObject2);
				System.out.println(boundSql.getSql());
				System.out.println();
			}
			//删除同一cachegroup关联缓存
			removeCacheByGroup(mt.getId(), mapperNameSpace);
		}
	} 
                            #location 35 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                             @SuppressWarnings("rawtypes")
	@Override
	public void onFinished(Invocation invocation,Object result) {
		Object[] args = invocation.getArgs();
		MappedStatement mt = (MappedStatement)args[0]; 
		
		String mapperNameSpace = mt.getId().substring(0, mt.getId().lastIndexOf(SPLIT_PONIT));
		
		QueryMethodCache cacheInfo = null;
		if(mt.getSqlCommandType().equals(SqlCommandType.SELECT)){	
			if(result == null)return;  
			if((cacheInfo = getQueryMethodCache(mt.getId())) == null)return;
			
			if(result instanceof List){
				List list = (List)result;
				if(list.isEmpty())return;
				result = cacheInfo.collectionResult ? result : list.get(0);
			}
			final String cacheKey = genarateQueryCacheKey(cacheInfo.keyPattern, args[1]);
			//按主键查询以及标记非引用关系的缓存直接读取缓存
			if(cacheInfo.isSecondQueryById() == false){
				if(cacheProvider.set(cacheKey,result, cacheInfo.expire)){
					if(logger.isDebugEnabled())logger.debug("_autocache_ method[{}] put result to cache，cacheKey:{}",mt.getId(),cacheKey);
				}
				//结果为集合的情况，增加key到cacheGroup
				if(cacheInfo.groupRalated){
					cacheProvider.putGroupKeys(cacheInfo.cacheGroupKey, cacheKey,cacheInfo.expire);
					logger.debug("_autocache_ method[{}] add key:[{}] to group key:[{}]",mt.getId(),cacheInfo.cacheGroupKey, cacheKey);
				}else{
					//
					cacheUniqueSelectRef(result, mt, cacheKey);
				}
			}else{
				//之前没有按主键的缓存，增加按主键缓存
				String idCacheKey = genarateQueryCacheKey(getQueryByPkMethodCache(mt.getId()).keyPattern,result);
				
				if(idCacheKey != null && cacheKey != null && cacheProvider.set(idCacheKey,result, cacheInfo.expire) 
						&& cacheProvider.set(cacheKey,idCacheKey, cacheInfo.expire)){
					if(logger.isDebugEnabled())logger.debug("_autocache_ method[{}] put result to cache，cacheKey:{},and add ref cacheKey:{}",mt.getId(),idCacheKey,cacheKey);
				}
			}
		}else{
			if(!cacheEnableMappers.contains(mapperNameSpace))return;
			//返回0，未更新成功
			if(result != null && ((int)result) == 0)return;
			if(updateCacheMethods.containsKey(mt.getId())){
				String cacheByPkKey = null;
				UpdateByPkMethodCache updateMethodCache = updateCacheMethods.get(mt.getId());
				if(updateMethodCache.sqlCommandType.equals(SqlCommandType.DELETE)){
					cacheByPkKey = genarateQueryCacheKey(updateMethodCache.keyPattern,args[1]);
					cacheProvider.remove(cacheByPkKey);
					if(logger.isDebugEnabled())logger.debug("_autocache_ method[{}] remove cacheKey:{} from cache",mt.getId(),cacheByPkKey);
				}else{
					cacheByPkKey = genarateQueryCacheKey(updateMethodCache.keyPattern,args[1]);
					boolean insertCommond = mt.getSqlCommandType().equals(SqlCommandType.INSERT);
					if(insertCommond || mt.getSqlCommandType().equals(SqlCommandType.UPDATE)){
						if(result != null){
							QueryMethodCache queryByPkMethodCache = getQueryByPkMethodCache(mt.getId());
							cacheProvider.set(cacheByPkKey,args[1], queryByPkMethodCache.expire);
							if(logger.isDebugEnabled())logger.debug("_autocache_ method[{}] update cacheKey:{}",mt.getId(),cacheByPkKey);
							//插入其他唯一字段引用
							if(insertCommond)cacheUniqueSelectRef(args[1], mt, cacheByPkKey);
							//
							addCurrentThreadCacheKey(cacheByPkKey);
						}
					}
				}				
			}else{//按条件删除和更新的情况
				try {					
					Executor executor = (Executor) invocation.getTarget();
					Object parameterObject = args[1];
					ResultHandler resultHandler = null;
					EntityInfo entityInfo = MybatisMapperParser.getEntityInfoByMapper(mapperNameSpace);
					MappedStatement statement = getQueryIdsMappedStatementForUpdateCache(mt,entityInfo);
					List<?> idsResult = executor.query(statement, parameterObject, RowBounds.DEFAULT, resultHandler);
					if(idsResult != null){
						for (Object id : idsResult) {							
							String cacheKey = entityInfo.getEntityClass().getSimpleName() + ".id:" + id.toString();
							cacheProvider.remove(cacheKey);
						}
						if(logger.isDebugEnabled())logger.debug("_autocache_ update Method[{}] executed,remove ralate cache {}.id:[{}]",mt.getId(),entityInfo.getEntityClass().getSimpleName(),idsResult);
					}
				} catch (Exception e) {
					logger.error("_autocache_ update Method[{}] remove ralate cache error",e);
				}
                
			}
			//删除同一cachegroup关联缓存
			removeCacheByGroup(mt.getId(), mapperNameSpace);
		}
	}