xref: /aosp_15_r20/external/auto/value/CHANGES.md (revision 1c2bbba85eccddce6de79cbbf1645fda32e723f0)
1*1c2bbba8SAndroid Build Coastguard Worker# AutoValue Changes
2*1c2bbba8SAndroid Build Coastguard Worker
3*1c2bbba8SAndroid Build Coastguard Worker**This document is obsolete.** For details of changes in releases since 1.5,
4*1c2bbba8SAndroid Build Coastguard Workersee the [releases page](https://github.com/google/auto/releases) for the Auto
5*1c2bbba8SAndroid Build Coastguard Workerproject.
6*1c2bbba8SAndroid Build Coastguard Worker
7*1c2bbba8SAndroid Build Coastguard Worker## 1.4 → 1.5
8*1c2bbba8SAndroid Build Coastguard Worker
9*1c2bbba8SAndroid Build Coastguard Worker### Functional changes
10*1c2bbba8SAndroid Build Coastguard Worker
11*1c2bbba8SAndroid Build Coastguard Worker* A workaround for older Eclipse versions has been removed. If you need to use
12*1c2bbba8SAndroid Build Coastguard Worker  an Eclipse version older than 4.5, you will need to stay on AutoValue 1.4.
13*1c2bbba8SAndroid Build Coastguard Worker
14*1c2bbba8SAndroid Build Coastguard Worker* The [retention](https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Retention.html)
15*1c2bbba8SAndroid Build Coastguard Worker  of the `@AutoValue` annotation has changed from `SOURCE` to `CLASS`. This
16*1c2bbba8SAndroid Build Coastguard Worker  means that it is possible for code-analysis tools to tell whether a class is
17*1c2bbba8SAndroid Build Coastguard Worker  an `@AutoValue`. AutoValue itself uses this to enforce the check that one
18*1c2bbba8SAndroid Build Coastguard Worker  `@AutoValue` class cannot extend another, even if the classes are compiled
19*1c2bbba8SAndroid Build Coastguard Worker  separately.
20*1c2bbba8SAndroid Build Coastguard Worker
21*1c2bbba8SAndroid Build Coastguard Worker* It is now an error if `@Memoized` is applied to a method not inside an
22*1c2bbba8SAndroid Build Coastguard Worker  `@AutoValue` class.
23*1c2bbba8SAndroid Build Coastguard Worker
24*1c2bbba8SAndroid Build Coastguard Worker* Type annotations are now handled more consistently. If `@Nullable` is a type
25*1c2bbba8SAndroid Build Coastguard Worker  annotation, a property of type `@Nullable Integer` will have that type used
26*1c2bbba8SAndroid Build Coastguard Worker  everywhere in the generated code. Associated bugs with nested type
27*1c2bbba8SAndroid Build Coastguard Worker  annotations, like `Outer.@Inner`, have been fixed.
28*1c2bbba8SAndroid Build Coastguard Worker
29*1c2bbba8SAndroid Build Coastguard Worker### Bugs fixed since 1.4.1
30*1c2bbba8SAndroid Build Coastguard Worker
31*1c2bbba8SAndroid Build Coastguard Worker* `@Memoized` methods can now throw checked exceptions. Previously this failed
32*1c2bbba8SAndroid Build Coastguard Worker  because the exceptions were not copied into the `throws` clause of the
33*1c2bbba8SAndroid Build Coastguard Worker  generated override, so the call to `super.foo()` did not compile.
34*1c2bbba8SAndroid Build Coastguard Worker
35*1c2bbba8SAndroid Build Coastguard Worker* The generated `hashCode()` method uses `h = (int) (h ^ longProperty)` rather
36*1c2bbba8SAndroid Build Coastguard Worker  than `h ^= longProperty` to avoid warnings about loss of precision.
37*1c2bbba8SAndroid Build Coastguard Worker
38*1c2bbba8SAndroid Build Coastguard Worker* Annotations are not copied from an abstract method to its implementation if
39*1c2bbba8SAndroid Build Coastguard Worker  they are not visible from the latter. This can happen if the `@AutoValue`
40*1c2bbba8SAndroid Build Coastguard Worker  inherits the abstract method from a class or interface in a different package.
41*1c2bbba8SAndroid Build Coastguard Worker
42*1c2bbba8SAndroid Build Coastguard Worker## 1.3 → 1.4
43*1c2bbba8SAndroid Build Coastguard Worker
44*1c2bbba8SAndroid Build Coastguard Worker*This is the last AutoValue version that compiles and runs on Java 6.* Future
45*1c2bbba8SAndroid Build Coastguard Workerversions will require at least Java 8 to run. We will continue to generate code
46*1c2bbba8SAndroid Build Coastguard Workerthat is compatible with Java 7, so AutoValue can be used with `javac -source 7
47*1c2bbba8SAndroid Build Coastguard Worker-target 7 -bootclasspath <rt.jar-from-jdk7>`, but using the `javac` from jdk8 or
48*1c2bbba8SAndroid Build Coastguard Workerlater.
49*1c2bbba8SAndroid Build Coastguard Worker
50*1c2bbba8SAndroid Build Coastguard Worker### Functional changes
51*1c2bbba8SAndroid Build Coastguard Worker
52*1c2bbba8SAndroid Build Coastguard Worker* Builder setters now reject a null parameter immediately unless the
53*1c2bbba8SAndroid Build Coastguard Worker  corresponding property is `@Nullable`. Previously this check happened at
54*1c2bbba8SAndroid Build Coastguard Worker  `build()` time, and in some cases didn't happen at all. This is the change
55*1c2bbba8SAndroid Build Coastguard Worker  that is most likely to affect existing code.
56*1c2bbba8SAndroid Build Coastguard Worker
57*1c2bbba8SAndroid Build Coastguard Worker* Added `@Memoized`. A `@Memoized` method will be overridden in the generated
58*1c2bbba8SAndroid Build Coastguard Worker  `AutoValue_Foo` class to save the value returned the first time it was called
59*1c2bbba8SAndroid Build Coastguard Worker  and reuse that every other time.
60*1c2bbba8SAndroid Build Coastguard Worker
61*1c2bbba8SAndroid Build Coastguard Worker* Generalized support for property builders. Now, in addition to being able to
62*1c2bbba8SAndroid Build Coastguard Worker  say `immutableListBuilder()` for a property of type `ImmutableList<T>`, you
63*1c2bbba8SAndroid Build Coastguard Worker  can say `fooBuilder()` for a property of an arbitrary type that has a builder
64*1c2bbba8SAndroid Build Coastguard Worker  following certain conventions. In particular, you can do this if the type of
65*1c2bbba8SAndroid Build Coastguard Worker  `foo()` is itself an `@AutoValue` class with a builder. The default value of
66*1c2bbba8SAndroid Build Coastguard Worker  `foo()`, if `fooBuilder()` is never called, is `fooBuilder().build()`.
67*1c2bbba8SAndroid Build Coastguard Worker
68*1c2bbba8SAndroid Build Coastguard Worker* If a property `foo()` or `getFoo()` has a builder method `fooBuilder()` then
69*1c2bbba8SAndroid Build Coastguard Worker  the property can not now be `@Nullable`. An `ImmutableList`, for example,
70*1c2bbba8SAndroid Build Coastguard Worker  starts off empty, not null, so `@Nullable` was misleading.
71*1c2bbba8SAndroid Build Coastguard Worker
72*1c2bbba8SAndroid Build Coastguard Worker* When an `@AutoValue` class `Foo` has a builder, the generated
73*1c2bbba8SAndroid Build Coastguard Worker  `AutoValue_Foo.Builder` has a constructor `AutoValue_Foo.Builder(Foo)`. That
74*1c2bbba8SAndroid Build Coastguard Worker  constructor was never documented and is now private. If you want to make a
75*1c2bbba8SAndroid Build Coastguard Worker  `Foo.Builder` from a `Foo`, `Foo` should have an abstract method `Builder
76*1c2bbba8SAndroid Build Coastguard Worker  toBuilder()`.
77*1c2bbba8SAndroid Build Coastguard Worker
78*1c2bbba8SAndroid Build Coastguard Worker  This change was necessary so that generalized property-builder support could
79*1c2bbba8SAndroid Build Coastguard Worker  know whether or not the built class needs to be convertible back into its
80*1c2bbba8SAndroid Build Coastguard Worker  builder. That's only necessary if there is a `toBuilder()`.
81*1c2bbba8SAndroid Build Coastguard Worker
82*1c2bbba8SAndroid Build Coastguard Worker* The Extension API is now a committed API, meaning we no longer warn that it is
83*1c2bbba8SAndroid Build Coastguard Worker  likely to change incompatibly. A
84*1c2bbba8SAndroid Build Coastguard Worker  [guide](https://github.com/google/auto/blob/main/value/userguide/extensions.md)
85*1c2bbba8SAndroid Build Coastguard Worker  gives tips on writing extensions.
86*1c2bbba8SAndroid Build Coastguard Worker
87*1c2bbba8SAndroid Build Coastguard Worker* Extensions can now return null rather than generated code. In that case the
88*1c2bbba8SAndroid Build Coastguard Worker  extension does not generate a class in the AutoValue hierarchy, but it can
89*1c2bbba8SAndroid Build Coastguard Worker  still do other things like error checking or generating side files.
90*1c2bbba8SAndroid Build Coastguard Worker
91*1c2bbba8SAndroid Build Coastguard Worker* Access modifiers like `protected` are copied from builder methods to their
92*1c2bbba8SAndroid Build Coastguard Worker  implementations, instead of the implementations always being public.
93*1c2bbba8SAndroid Build Coastguard Worker  Change by @torquestomp.
94*1c2bbba8SAndroid Build Coastguard Worker
95*1c2bbba8SAndroid Build Coastguard Worker* AutoAnnotation now precomputes parts of the `hashCode` that are constant
96*1c2bbba8SAndroid Build Coastguard Worker  because they come from defaulted methods. This avoids warnings about integer
97*1c2bbba8SAndroid Build Coastguard Worker  overflow from tools that check that.
98*1c2bbba8SAndroid Build Coastguard Worker
99*1c2bbba8SAndroid Build Coastguard Worker* If a property is called `oAuth()`, its setter can be called
100*1c2bbba8SAndroid Build Coastguard Worker  `setOAuth(x)`. Previously it had to be `setoAuth(x)`, which is still allowed.
101*1c2bbba8SAndroid Build Coastguard Worker
102*1c2bbba8SAndroid Build Coastguard Worker## Bugs fixed
103*1c2bbba8SAndroid Build Coastguard Worker
104*1c2bbba8SAndroid Build Coastguard Worker* AutoAnnotation now correctly handles types like `Class<? extends
105*1c2bbba8SAndroid Build Coastguard Worker  Annotation>[]`. Previously it would try to create a generic array, which Java
106*1c2bbba8SAndroid Build Coastguard Worker  doesn't allow. Change by @lukesandberg.
107*1c2bbba8SAndroid Build Coastguard Worker
108*1c2bbba8SAndroid Build Coastguard Worker* We guard against spurious exceptions due to a JDK bug in reading resources
109*1c2bbba8SAndroid Build Coastguard Worker  from jars. (#365)
110*1c2bbba8SAndroid Build Coastguard Worker
111*1c2bbba8SAndroid Build Coastguard Worker* We don't propagate an exception if a corrupt jar is found in extension
112*1c2bbba8SAndroid Build Coastguard Worker  loading.
113*1c2bbba8SAndroid Build Coastguard Worker
114*1c2bbba8SAndroid Build Coastguard Worker* AutoValue is ready for Java 9, where public classes are not necessarily
115*1c2bbba8SAndroid Build Coastguard Worker  accessible, and javax.annotation.Generated is not necessarily present.
116*1c2bbba8SAndroid Build Coastguard Worker
117*1c2bbba8SAndroid Build Coastguard Worker* AutoValue now works correctly even if the version of AutoValue in the
118*1c2bbba8SAndroid Build Coastguard Worker  `-classpath` is older than the one in the `-processorpath`.
119*1c2bbba8SAndroid Build Coastguard Worker
120*1c2bbba8SAndroid Build Coastguard Worker* Builders now behave correctly when there is a non-optional property called
121*1c2bbba8SAndroid Build Coastguard Worker  `missing`. Previously a variable-hiding problem meant that we didn't detect
122*1c2bbba8SAndroid Build Coastguard Worker  when it wasn't set.
123*1c2bbba8SAndroid Build Coastguard Worker
124*1c2bbba8SAndroid Build Coastguard Worker* If `@AutoValue class Foo` has a builder, we always generated two constructors,
125*1c2bbba8SAndroid Build Coastguard Worker  `Builder()` and `Builder(Foo)`, but we only used the second one if `Foo` had a
126*1c2bbba8SAndroid Build Coastguard Worker  `toBuilder()` method. Now we only generate that constructor if it is
127*1c2bbba8SAndroid Build Coastguard Worker  needed. That avoids warnings about unused code.
128*1c2bbba8SAndroid Build Coastguard Worker
129*1c2bbba8SAndroid Build Coastguard Worker* `@AutoAnnotation` now works when the annotation and the factory method are in
130*1c2bbba8SAndroid Build Coastguard Worker  the default (unnamed) package.
131*1c2bbba8SAndroid Build Coastguard Worker
132*1c2bbba8SAndroid Build Coastguard Worker## 1.2 → 1.3
133*1c2bbba8SAndroid Build Coastguard Worker
134*1c2bbba8SAndroid Build Coastguard Worker### Functional changes
135*1c2bbba8SAndroid Build Coastguard Worker
136*1c2bbba8SAndroid Build Coastguard Worker* Support for TYPE_USE `@Nullable`.
137*1c2bbba8SAndroid Build Coastguard Worker  This is https://github.com/google/auto/pull/293 by @brychcy.
138*1c2bbba8SAndroid Build Coastguard Worker
139*1c2bbba8SAndroid Build Coastguard Worker* Restructured the code in AutoValueProcessor for handling extensions, to get
140*1c2bbba8SAndroid Build Coastguard Worker  rid of warnings about abstract methods when those methods are going to be
141*1c2bbba8SAndroid Build Coastguard Worker  implemented by an extension, and to fix a bug where extensions would not work
142*1c2bbba8SAndroid Build Coastguard Worker  right if there was a toBuilder() method. Some of the code in this change is
143*1c2bbba8SAndroid Build Coastguard Worker  based on https://github.com/google/auto/pull/299 by @rharter.
144*1c2bbba8SAndroid Build Coastguard Worker
145*1c2bbba8SAndroid Build Coastguard Worker* Added support for "optional getters", where a getter in an AutoValue Builder
146*1c2bbba8SAndroid Build Coastguard Worker  can have type `Optional<T>` and it will return `Optional.of(x)` where `x` is
147*1c2bbba8SAndroid Build Coastguard Worker  the value that has been set in the Builder, or `Optional.empty()` if no value
148*1c2bbba8SAndroid Build Coastguard Worker  has been set.
149*1c2bbba8SAndroid Build Coastguard Worker
150*1c2bbba8SAndroid Build Coastguard Worker* In AutoValue builders, added support for setting a property of type
151*1c2bbba8SAndroid Build Coastguard Worker  `Optional<T>` via a setter with an argument of type `T`.
152*1c2bbba8SAndroid Build Coastguard Worker
153*1c2bbba8SAndroid Build Coastguard Worker* Added logic to AutoValue to detect the confusing case where you think you
154*1c2bbba8SAndroid Build Coastguard Worker  are using JavaBeans conventions (like getFoo()) but you aren't because at
155*1c2bbba8SAndroid Build Coastguard Worker  least one method isn't.
156*1c2bbba8SAndroid Build Coastguard Worker
157*1c2bbba8SAndroid Build Coastguard Worker* Added a README.md describing EscapeVelocity.
158*1c2bbba8SAndroid Build Coastguard Worker
159*1c2bbba8SAndroid Build Coastguard Worker### Bugs fixed
160*1c2bbba8SAndroid Build Coastguard Worker
161*1c2bbba8SAndroid Build Coastguard Worker* Allow an `@AutoValue.Builder` to extend a parent builder using the `<B extends
162*1c2bbba8SAndroid Build Coastguard Worker  Builder<B>>` idiom.
163*1c2bbba8SAndroid Build Coastguard Worker
164*1c2bbba8SAndroid Build Coastguard Worker* AutoAnnotation now factors in package names when detecting
165*1c2bbba8SAndroid Build Coastguard Worker  overloads. Previously it treated all annotations with the same SimpleName as
166*1c2bbba8SAndroid Build Coastguard Worker  being overload attempts.
167*1c2bbba8SAndroid Build Coastguard Worker
168*1c2bbba8SAndroid Build Coastguard Worker* Removed an inaccurate javadoc reference, which referred to an
169*1c2bbba8SAndroid Build Coastguard Worker  artifact from an earlier draft version of the Extensions API. This is
170*1c2bbba8SAndroid Build Coastguard Worker  https://github.com/google/auto/pull/322 by @lucastsa.
171*1c2bbba8SAndroid Build Coastguard Worker
172*1c2bbba8SAndroid Build Coastguard Worker## 1.1 → 1.2
173*1c2bbba8SAndroid Build Coastguard Worker
174*1c2bbba8SAndroid Build Coastguard Worker### Functional changes
175*1c2bbba8SAndroid Build Coastguard Worker
176*1c2bbba8SAndroid Build Coastguard Worker  * A **provisional** extension API has been introduced. This **will change**
177*1c2bbba8SAndroid Build Coastguard Worker    in a later release. If you want to use it regardless, see the
178*1c2bbba8SAndroid Build Coastguard Worker    [AutoValueExtension] class.
179*1c2bbba8SAndroid Build Coastguard Worker
180*1c2bbba8SAndroid Build Coastguard Worker  * Properties of primitive array type (e.g. `byte[]`) are no longer cloned
181*1c2bbba8SAndroid Build Coastguard Worker    when read. If your `@AutoValue` class includes an array property, by default
182*1c2bbba8SAndroid Build Coastguard Worker    it will get a compiler warning, which can be suppressed with
183*1c2bbba8SAndroid Build Coastguard Worker    `@SuppressWarnings("mutable")`.
184*1c2bbba8SAndroid Build Coastguard Worker
185*1c2bbba8SAndroid Build Coastguard Worker  * An `@AutoValue.Builder` type can now define both the setter and builder
186*1c2bbba8SAndroid Build Coastguard Worker    methods like so:
187*1c2bbba8SAndroid Build Coastguard Worker
188*1c2bbba8SAndroid Build Coastguard Worker    ```
189*1c2bbba8SAndroid Build Coastguard Worker      ...
190*1c2bbba8SAndroid Build Coastguard Worker      abstract void setStrings(ImmutableList<String>);
191*1c2bbba8SAndroid Build Coastguard Worker      abstract ImmutableList.Builder<String> stringsBuilder();
192*1c2bbba8SAndroid Build Coastguard Worker      ...
193*1c2bbba8SAndroid Build Coastguard Worker    ```
194*1c2bbba8SAndroid Build Coastguard Worker    At runtime, if `stringsBuilder()...` is called then it is an error to call
195*1c2bbba8SAndroid Build Coastguard Worker    `setStrings(...)` afterwards.
196*1c2bbba8SAndroid Build Coastguard Worker
197*1c2bbba8SAndroid Build Coastguard Worker  * The classes in the autovalue jar are now shaded with a `$` so they never
198*1c2bbba8SAndroid Build Coastguard Worker    appear in IDE autocompletion.
199*1c2bbba8SAndroid Build Coastguard Worker
200*1c2bbba8SAndroid Build Coastguard Worker  * AutoValue now uses its own implementation of a subset of Apache Velocity,
201*1c2bbba8SAndroid Build Coastguard Worker    so there will no longer be problems with interference between the Velocity
202*1c2bbba8SAndroid Build Coastguard Worker    that was bundled with AutoValue and other versions that might be present.
203*1c2bbba8SAndroid Build Coastguard Worker
204*1c2bbba8SAndroid Build Coastguard Worker### Bugs fixed
205*1c2bbba8SAndroid Build Coastguard Worker
206*1c2bbba8SAndroid Build Coastguard Worker  * Explicit check for nested `@AutoValue` classes being private, or not being
207*1c2bbba8SAndroid Build Coastguard Worker    static. Otherwise the compiler errors could be hard to understand,
208*1c2bbba8SAndroid Build Coastguard Worker    especially in IDEs.
209*1c2bbba8SAndroid Build Coastguard Worker
210*1c2bbba8SAndroid Build Coastguard Worker  * An Eclipse bug that could occasionally lead to exceptions in the IDE has
211*1c2bbba8SAndroid Build Coastguard Worker    been fixed (GitHub issue #200).
212*1c2bbba8SAndroid Build Coastguard Worker
213*1c2bbba8SAndroid Build Coastguard Worker  * Fixed a bug where AutoValue generated incorrect code if a method with a
214*1c2bbba8SAndroid Build Coastguard Worker    type parameter was inherited by a class that supplies a concrete type for
215*1c2bbba8SAndroid Build Coastguard Worker    that parameter. For example `StringIterator implements Iterator<String>`,
216*1c2bbba8SAndroid Build Coastguard Worker    where the type of `next()` is String, not `T`.
217*1c2bbba8SAndroid Build Coastguard Worker
218*1c2bbba8SAndroid Build Coastguard Worker  * In `AutoValueProcessor`, fixed an exception that happened if the same
219*1c2bbba8SAndroid Build Coastguard Worker    abstract method was inherited from more than one parent (Github Issue #267).
220*1c2bbba8SAndroid Build Coastguard Worker
221*1c2bbba8SAndroid Build Coastguard Worker  * AutoValue now works correctly in an environment where
222*1c2bbba8SAndroid Build Coastguard Worker    `@javax.annotation.Generated` does not exist.
223*1c2bbba8SAndroid Build Coastguard Worker
224*1c2bbba8SAndroid Build Coastguard Worker  * Properties marked `@Nullable` now get `@Nullable` on the corresponding
225*1c2bbba8SAndroid Build Coastguard Worker    constructor parameters in the generated class.
226*1c2bbba8SAndroid Build Coastguard Worker
227*1c2bbba8SAndroid Build Coastguard Worker## 1.0 → 1.1
228*1c2bbba8SAndroid Build Coastguard Worker
229*1c2bbba8SAndroid Build Coastguard Worker### Functional changes
230*1c2bbba8SAndroid Build Coastguard Worker
231*1c2bbba8SAndroid Build Coastguard Worker  * Adds builders to AutoValue. Builders are nested classes annotated with
232*1c2bbba8SAndroid Build Coastguard Worker    `@AutoValue.Builder`.
233*1c2bbba8SAndroid Build Coastguard Worker
234*1c2bbba8SAndroid Build Coastguard Worker  * Annotates constructor parameters with `@Nullable` if the corresponding
235*1c2bbba8SAndroid Build Coastguard Worker    property methods are `@Nullable`.
236*1c2bbba8SAndroid Build Coastguard Worker
237*1c2bbba8SAndroid Build Coastguard Worker  * Changes Maven shading so org.apache.commons is shaded.
238*1c2bbba8SAndroid Build Coastguard Worker
239*1c2bbba8SAndroid Build Coastguard Worker  * Copies a `@GwtCompatible` annotation from the `@AutoValue` class to its
240*1c2bbba8SAndroid Build Coastguard Worker    implementation subclass.
241*1c2bbba8SAndroid Build Coastguard Worker
242*1c2bbba8SAndroid Build Coastguard Worker### Bugs fixed
243*1c2bbba8SAndroid Build Coastguard Worker
244*1c2bbba8SAndroid Build Coastguard Worker  * Works around a bug in the Eclipse compiler that meant that annotations
245*1c2bbba8SAndroid Build Coastguard Worker    would be incorrectly copied from `@AutoValue` methods to their
246*1c2bbba8SAndroid Build Coastguard Worker    implementations.
247*1c2bbba8SAndroid Build Coastguard Worker
248*1c2bbba8SAndroid Build Coastguard Worker## 1.0 (Initial Release)
249*1c2bbba8SAndroid Build Coastguard Worker
250*1c2bbba8SAndroid Build Coastguard Worker  * Allows automatic generation of value type implementations
251*1c2bbba8SAndroid Build Coastguard Worker
252*1c2bbba8SAndroid Build Coastguard Worker    See [the AutoValue User's Guide](userguide/index.md)
253*1c2bbba8SAndroid Build Coastguard Worker
254*1c2bbba8SAndroid Build Coastguard Worker
255*1c2bbba8SAndroid Build Coastguard Worker[AutoValueExtension]: src/main/java/com/google/auto/value/extension/AutoValueExtension.java
256