Skip to content

Allow to inject enum with package visibility [SPR-16284] #20831

Closed
@spring-projects-issues

Description

@spring-projects-issues

Hans Desmet opened SPR-16284 and commented

A class with package visibility can be injected in a bean.
An enum can only be injected if it has public visibility.
Given a class

class MyClass {
  private final String value;
  public MyClass(String value) {
    this.value = value;
  }	
}

an enum

enum MyEnum {
  VALUE
}

a bean class

class MyBean {
  private final MyClass myClass;
  private final MyEnum myEnum;
  public MyBean(MyClass myClass, MyEnum myEnum) {
    this.myClass = myClass;
    this.myEnum = myEnum;
  }
}

and following bean definition:

<bean class='enumproblem.MyBean'>
  <constructor-arg value='value'/>
  <constructor-arg value='VALUE'/>
</bean>

you get an exception:java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'enumproblem.MyEnum': no matching editors or conversion strategy found

When you change the visibility of the enum to public, the exception dissapears.


Affects: 5.0.2

Reference URL: https://github.com/desmethans/enumproblem1.git

Issue Links:

Referenced from: commits 4bb8375, 9beb978

Backported to: 4.3.14

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions