• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

raphw / byte-buddy / #811

03 Nov 2025 10:41AM UTC coverage: 83.677% (-0.3%) from 84.023%
#811

push

raphw
Fix null handling.

0 of 1 new or added line in 1 file covered. (0.0%)

791 existing lines in 12 files now uncovered.

29814 of 35630 relevant lines covered (83.68%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/byte-buddy-dep/src/main/java/net/bytebuddy/build/SafeVarargsPlugin.java
1
/*
2
 * Copyright 2014 - Present Rafael Winterhalter
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.bytebuddy.build;
17

18
import net.bytebuddy.asm.MemberAttributeExtension;
19
import net.bytebuddy.description.method.MethodDescription;
20
import net.bytebuddy.description.type.TypeDescription;
21
import net.bytebuddy.dynamic.ClassFileLocator;
22
import net.bytebuddy.dynamic.DynamicType;
23
import net.bytebuddy.implementation.attribute.AnnotationValueFilter;
24
import net.bytebuddy.implementation.attribute.MethodAttributeAppender;
25
import org.objectweb.asm.AnnotationVisitor;
26
import org.objectweb.asm.MethodVisitor;
27

28
import java.lang.annotation.Documented;
29
import java.lang.annotation.ElementType;
30
import java.lang.annotation.Retention;
31
import java.lang.annotation.RetentionPolicy;
32
import java.lang.annotation.Target;
33

34
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
35
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
36

37
/**
38
 * A plugin that allows for adding a {@code java.lang.SafeVarargs} annotation even if compiled prior to Java 7
39
 * which introduces this annotation. As the annotation is not present on previous JVM versions, it is ignored
40
 * at runtime for older JVM versions what makes this approach feasible.
41
 */
42
@HashCodeAndEqualsPlugin.Enhance
43
public class SafeVarargsPlugin extends Plugin.ForElementMatcher implements Plugin.Factory {
44

45
    /**
46
     * Creates a new plugin for creating repeated annotations.
47
     */
48
    public SafeVarargsPlugin() {
49
        super(declaresMethod(isAnnotatedWith(Enhance.class)));
1✔
50
    }
1✔
51

52
    /**
53
     * {@inheritDoc}
54
     */
55
    public Plugin make() {
UNCOV
56
        return this;
×
57
    }
58

59
    /**
60
     * {@inheritDoc}
61
     */
62
    public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) {
63
        return builder.visit(new MemberAttributeExtension.ForMethod()
1✔
64
                .attribute(SafeVarargsAppender.INSTANCE)
1✔
65
                .on(isAnnotatedWith(Enhance.class)));
1✔
66
    }
67

68
    /**
69
     * {@inheritDoc}
70
     */
71
    public void close() {
72
        /* do nothing */
UNCOV
73
    }
×
74

75
    /**
76
     * Defines a safe-varargs annotation.
77
     */
78
    @Documented
79
    @Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
80
    @Retention(RetentionPolicy.RUNTIME)
81
    public @interface Enhance {
82
        /* empty */
83
    }
84

85
    /**
86
     * Appends the varargs annotation.
87
     */
88
    protected enum SafeVarargsAppender implements MethodAttributeAppender, MethodAttributeAppender.Factory {
1✔
89

90
        /**
91
         * The singleton instance.
92
         */
93
        INSTANCE;
1✔
94

95
        /**
96
         * {@inheritDoc}
97
         */
98
        public MethodAttributeAppender make(TypeDescription typeDescription) {
99
            return this;
1✔
100
        }
101

102
        /**
103
         * {@inheritDoc}
104
         */
105
        public void apply(MethodVisitor methodVisitor, MethodDescription methodDescription, AnnotationValueFilter annotationValueFilter) {
106
            if (!methodDescription.isVarArgs()) {
1✔
107
                throw new IllegalStateException(methodDescription + " does not have variable arguments");
1✔
108
            } else if (!methodDescription.isConstructor() && !methodDescription.isStatic() && !methodDescription.isFinal()) {
1✔
109
                throw new IllegalStateException(methodDescription + " is neither a constructor or final and cannot declare safe varargs");
1✔
110
            }
111
            AnnotationVisitor visitor = methodVisitor.visitAnnotation("Ljava/lang/SafeVarargs;", true);
1✔
112
            if (visitor != null) {
1✔
113
                visitor.visitEnd();
1✔
114
            }
115
        }
1✔
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc