RFR: 8345614: Improve AnnotationFormatError message for duplicate annotation interfaces

Scott Marlow duke at openjdk.org
Thu Dec 5 23:30:40 UTC 2024


On Thu, 5 Dec 2024 23:24:56 GMT, Scott Marlow <duke at openjdk.org> wrote:

>> I made a quick test for this, but you might not want to include it if you aim to backport this improvement to LTS releases as it uses the recently-finalized ClassFile API.
>> 
>> 
>> /*
>>  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
>>  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>  *
>>  * This code is free software; you can redistribute it and/or modify it
>>  * under the terms of the GNU General Public License version 2 only, as
>>  * published by the Free Software Foundation.
>>  *
>>  * This code is distributed in the hope that it will be useful, but WITHOUT
>>  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>  * version 2 for more details (a copy is included in the LICENSE file that
>>  * accompanied this code).
>>  *
>>  * You should have received a copy of the GNU General Public License version
>>  * 2 along with this work; if not, write to the Free Software Foundation,
>>  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
>>  *
>>  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
>>  * or visit www.oracle.com if you need additional information or have any
>>  * questions.
>>  */
>> 
>> /*
>>  * @test
>>  * @bug 8345614
>>  * @summary Ensure message for duplicated annotations mention problematic class
>>  * @library /test/lib
>>  */
>> 
>> import java.lang.annotation.AnnotationFormatError;
>> import java.lang.classfile.Annotation;
>> import java.lang.classfile.ClassFile;
>> import java.lang.classfile.ClassTransform;
>> import java.lang.classfile.FieldTransform;
>> import java.lang.classfile.MethodTransform;
>> import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
>> import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute;
>> import java.lang.constant.ClassDesc;
>> import java.nio.file.Path;
>> import java.util.List;
>> 
>> import jdk.test.lib.ByteCodeLoader;
>> 
>> public class DuplicateAnnotationsTest {
>>     public static void main(String... args) throws Throwable {
>>         ClassFile cf = ClassFile.of();
>>         Path annoDuplicatedClass = Path.of(System.getProperty("test.classes")).resolve("AnnotationDuplicated.class");
>> 
>>         Annotation annotation = Annotation.of(ClassDesc.of("java.lang.Deprecated"));
>>         RuntimeVisibleAnnotationsAttribute rvaa = RuntimeVisibleAnnotationsAttribute.of(
>>                 List.of(annotation, annotation)
>>       ...
>
>> I made a quick test for this, but you might not want to include it if you aim to backport this improvement to LTS releases as it uses the recently-finalized ClassFile API.
> 
> Excellent, I'm +1000 for adding your test, thank you very much for creating it!  Can you create a pr against https://github.com/scottmarlow/jdk/tree/AnnotationParser_should_include_container_Duplicate_annotation_error or add the commit directly to this pr?

> @scottmarlow I plan to do a separate PR to add this test; so we get a clean commit that can be easily backported to 24 and existing LTS versions.

Thanks, that sounds great as well!

Thanks to you and others in the community that helped me with this!

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22581#issuecomment-2521713958


More information about the core-libs-dev mailing list