求这个问题解决方法 java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at cn.com.lundong.feishu.core.contact.service.impl.FeishuUserServiceImpl.getUserByOpenId(FeishuUserServiceImpl.java:354)
at cn.com.lundong.feishu.core.contact.service.impl.FeishuUserServiceImpl$$FastClassBySpringCGLIB$$a5091579.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)


        LambdaQueryWrapper<FeishuUserPo> queryWrapper = Wrappers.<FeishuUserPo>lambdaQuery()
                .eq(FeishuUserPo::getTenantKey, tenantKey)
                .eq(FeishuUserPo::getAppId, appId)
                .eq(FeishuUserPo::getOpenId, openId)
                .eq(FeishuUserPo::getAuthorize, 1)
                .orderByAsc(FeishuUserPo::getCreateTime);
      

        List<FeishuUserPo> feishuUserPos = this.baseMapper.selectList(queryWrapper);

        if (feishuUserPos !=null && feishuUserPos.size() > 0){
            return  feishuUserPos.get(0);
        }
             return null;
    }

检查 FeishuUserServiceImpl.java 文件 354 行代码,List 为空时获取了索引为 0 的元素。

检查一下根据查询条件(queryWrapper )查询到的数据是不是为空,数据库没有满足查询条件的数据。