Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert bugfix around setting properties and nullability #4869

Merged
merged 5 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ public final void set(@NonNull B bean, @Nullable P value) {
if (value != null && !ReflectionUtils.getWrapperType(getType()).isInstance(value)) {
throw new IllegalArgumentException("Specified value [" + value + "] is not of the correct type: " + getType());
}
/*
if (value == null && isNonNull()) {
throw new IllegalArgumentException("Null values not supported by property: " + getName());
}
*/
writeInternal(bean, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.micronaut.inject.visitor.beans
import io.micronaut.core.annotation.Introspected
import io.micronaut.core.beans.BeanIntrospection
import io.micronaut.core.beans.BeanIntrospector
import spock.lang.PendingFeature
import spock.lang.Specification

import javax.inject.Singleton
Expand Down Expand Up @@ -53,7 +54,18 @@ class BeanIntrospectorSpec extends Specification {
void "test find introspections"() {
expect:
BeanIntrospector.SHARED.findIntrospections(Introspected).size() > 0
BeanIntrospector.SHARED.findIntrospections(Introspected, "io.micronaut.inject.visitor.beans").size() == 3
BeanIntrospector.SHARED.findIntrospections(Introspected, "io.micronaut.inject.visitor.beans").size() == 5
BeanIntrospector.SHARED.findIntrospections(Introspected, "blah").size() == 0
}

@PendingFeature
void "test instantiating with a non null argument with null"() {
BeanIntrospection<NonNullBean> introspection = BeanIntrospection.getIntrospection(NonNullBean)

when:
introspection.instantiate(false, [null] as Object[])

then:
def ex = thrown(IllegalArgumentException)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.micronaut.inject.visitor.beans

import io.micronaut.core.beans.BeanWrapper
import spock.lang.PendingFeature
import spock.lang.Specification

class BeanWrapperSpec extends Specification {
Expand All @@ -25,4 +26,22 @@ class BeanWrapperSpec extends Specification {
wrapper.getRequiredProperty("name", String) == 'Fred'
wrapper.getRequiredProperty("age", Integer.class) == 10
}

@PendingFeature
void "test setting a non null with null"() {
when:"A wrapper is obtained"
def bean = new NullabilityBean()
BeanWrapper<NullabilityBean> wrapper = BeanWrapper.getWrapper(bean)

then:"it is correct"
wrapper.bean == bean

when:
wrapper.setProperty("name", null)

then:
def ex = thrown(IllegalArgumentException)
ex.message == "Null values not supported by property: name"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.micronaut.inject.visitor.beans;

import edu.umd.cs.findbugs.annotations.NonNull;
import io.micronaut.core.annotation.Creator;
import io.micronaut.core.annotation.Introspected;

@Introspected
public class NonNullBean {

@NonNull
private final String value;

public NonNullBean(@NonNull String value) {
this.value = value;
}

@NonNull
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.micronaut.inject.visitor.beans;

import edu.umd.cs.findbugs.annotations.NonNull;
import io.micronaut.core.annotation.Introspected;

@Introspected
public class NullabilityBean {

@NonNull
String name;

@NonNull
public String getName() {
return name;
}

public void setName(@NonNull String name) {
this.name = name;
}


}