Skip to content

convertRegistryIdsToRegistries 时候tmpRegistries.add报错 #5250

@renchengpeng

Description

@renchengpeng
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.3
  • Operating System version: windows8
  • Java version: 1.8

Steps to reproduce this issue

  1. 在消费端使用注解@reference时候,其中registry中指定了具体的值(注册配置对应的id属性)后,在启动解析注解时候,会执行configureRegistryConfigs方法解析@reference中的registry属性值,在改属性里面设置了值后,会执行getBeans方法,在getBeans方法中会返回Collections.unmodifiableList集合

  2. 在步骤1中返回的集合,会在接下来调用相应的ReferenceBean的方法setRegistries,设置到属性List registries中,此时的list是Collections.unmodifiableList实现。

  3. 接下来,在ReferenceBean初始化中,会先检测注册配置,调用checkRegistry方法,在里面会将RegistryIds 转换为registries,即在convertRegistryIdsToRegistries方法中完成。

  4. convertRegistryIdsToRegistries 方法在有registryIds时候,有如下代码:
    String[] ids = COMMA_SPLIT_PATTERN.split(registryIds); List<RegistryConfig> tmpRegistries = CollectionUtils.isNotEmpty(registries) ? registries : new ArrayList<>(); Arrays.stream(ids).forEach(id -> { if (tmpRegistries.stream().noneMatch(reg -> reg.getId().equals(id))) { tmpRegistries.add(ConfigManager.getInstance().getRegistry(id).orElseGet(() -> { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setId(id); registryConfig.refresh(); return registryConfig; })); } });
    其中tmpRegistries.add时候会报错,因为此时的tmpRegistries是Collections.unmodifiableList实例,导致无法添加

Pls. provide [GitHub address] to reproduce this issue.

改变下类型,使其可以进行添加

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions