You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed a bug when you have for example an annotation on your interface and inside a string property you have nested quotes containing something that looks like: . inside the nested quotes.
This leads immutables to believe what is inside the nested quotes is a Java Class that needs to be imported, but if this does not exist it causes compilation errors.
This only seems to happen if inside the quotes there is a string with a '.' and the first character after the '.' is an upper case letter.
A minimal example is as follows:
importcom.fasterxml.jackson.annotation.JsonPropertyDescription;
importorg.immutables.value.Value;
@Value.Immutable@Value.Style(passAnnotations = {JsonPropertyDescription.class})
publicinterfaceMinimalImmutablesTest {
@JsonPropertyDescription(value = "This is a string with nested quotes \"a.B\"")
intvalue();
}
Which generates the following class file (note the import at the top):
importa.B;
importcom.fasterxml.jackson.annotation.JsonPropertyDescription;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Objects;
importorg.immutables.value.Generated;
/** * Immutable implementation of {@link MinimalImmutablesTest}. * <p> * Use the builder to create immutable instances: * {@code ImmutableMinimalImmutablesTest.builder()}. */@Generated(from = "MinimalImmutablesTest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
publicfinalclassImmutableMinimalImmutablesTestimplementsMinimalImmutablesTest {
privatefinalintvalue;
privateImmutableMinimalImmutablesTest(intvalue) {
this.value = value;
}
/** * @return The value of the {@code value} attribute */@JsonPropertyDescription("This is a string with nested quotes \"B\"")
@Overridepublicintvalue() {
returnvalue;
}
/** * Copy the current immutable object by setting a value for the {@link MinimalImmutablesTest#value() value} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for value * @return A modified copy of the {@code this} object */publicfinalImmutableMinimalImmutablesTestwithValue(intvalue) {
if (this.value == value) returnthis;
returnnewImmutableMinimalImmutablesTest(value);
}
/** * This instance is equal to all instances of {@code ImmutableMinimalImmutablesTest} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */@Overridepublicbooleanequals(Objectanother) {
if (this == another) returntrue;
returnanotherinstanceofImmutableMinimalImmutablesTest
&& equalTo(0, (ImmutableMinimalImmutablesTest) another);
}
privatebooleanequalTo(intsynthetic, ImmutableMinimalImmutablesTestanother) {
returnvalue == another.value;
}
/** * Computes a hash code from attributes: {@code value}. * @return hashCode value */@OverridepublicinthashCode() {
inth = 5381;
h += (h << 5) + value;
returnh;
}
/** * Prints the immutable value {@code MinimalImmutablesTest} with attribute values. * @return A string representation of the value */@OverridepublicStringtoString() {
return"MinimalImmutablesTest{"
+ "value=" + value
+ "}";
}
/** * Creates an immutable copy of a {@link MinimalImmutablesTest} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable MinimalImmutablesTest instance */publicstaticImmutableMinimalImmutablesTestcopyOf(MinimalImmutablesTestinstance) {
if (instanceinstanceofImmutableMinimalImmutablesTest) {
return (ImmutableMinimalImmutablesTest) instance;
}
returnImmutableMinimalImmutablesTest.builder()
.from(instance)
.build();
}
/** * Creates a builder for {@link ImmutableMinimalImmutablesTest ImmutableMinimalImmutablesTest}. * <pre> * ImmutableMinimalImmutablesTest.builder() * .value(int) // required {@link MinimalImmutablesTest#value() value} * .build(); * </pre> * @return A new ImmutableMinimalImmutablesTest builder */publicstaticImmutableMinimalImmutablesTest.Builderbuilder() {
returnnewImmutableMinimalImmutablesTest.Builder();
}
/** * Builds instances of type {@link ImmutableMinimalImmutablesTest ImmutableMinimalImmutablesTest}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances.</em> */@Generated(from = "MinimalImmutablesTest", generator = "Immutables")
publicstaticfinalclassBuilder {
privatestaticfinallongINIT_BIT_VALUE = 0x1L;
privatelonginitBits = 0x1L;
privateintvalue;
privateBuilder() {
}
/** * Fill a builder with attribute values from the provided {@code MinimalImmutablesTest} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */publicfinalBuilderfrom(MinimalImmutablesTestinstance) {
Objects.requireNonNull(instance, "instance");
this.value(instance.value());
returnthis;
}
/** * Initializes the value for the {@link MinimalImmutablesTest#value() value} attribute. * @param value The value for value * @return {@code this} builder for use in a chained invocation */publicfinalBuildervalue(intvalue) {
this.value = value;
initBits &= ~INIT_BIT_VALUE;
returnthis;
}
/** * Builds a new {@link ImmutableMinimalImmutablesTest ImmutableMinimalImmutablesTest}. * @return An immutable instance of MinimalImmutablesTest * @throws java.lang.IllegalStateException if any required attributes are missing */publicImmutableMinimalImmutablesTestbuild() {
if (initBits != 0) {
thrownewIllegalStateException(formatRequiredAttributesMessage());
}
returnnewImmutableMinimalImmutablesTest(value);
}
privateStringformatRequiredAttributesMessage() {
List<String> attributes = newArrayList<>();
if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value");
return"Cannot build MinimalImmutablesTest, some of required attributes are not set " + attributes;
}
}
}
The text was updated successfully, but these errors were encountered:
harrismirza
changed the title
Issue with nested quotes in strings when using passAnnotation
Issue with nested quotes in strings when using passAnnotations
Mar 21, 2024
Hi all,
I noticed a bug when you have for example an annotation on your interface and inside a string property you have nested quotes containing something that looks like: . inside the nested quotes.
This leads immutables to believe what is inside the nested quotes is a Java Class that needs to be imported, but if this does not exist it causes compilation errors.
This only seems to happen if inside the quotes there is a string with a '.' and the first character after the '.' is an upper case letter.
A minimal example is as follows:
Which generates the following class file (note the import at the top):
The text was updated successfully, but these errors were encountered: