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

raphw / byte-buddy / #717

17 Jan 2025 09:06PM UTC coverage: 85.373% (-0.1%) from 85.479%
#717

push

raphw
Fix build.

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

572 existing lines in 8 files now uncovered.

28973 of 33937 relevant lines covered (85.37%)

0.85 hits per line

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

29.63
/byte-buddy-dep/src/main/java/net/bytebuddy/utility/OpenedClassReader.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.utility;
17

18
import net.bytebuddy.ClassFileVersion;
19
import net.bytebuddy.build.AccessControllerPlugin;
20
import net.bytebuddy.utility.privilege.GetSystemPropertyAction;
21
import org.objectweb.asm.ClassReader;
22
import org.objectweb.asm.Opcodes;
23

24
import java.security.PrivilegedAction;
25

26
/**
27
 * A factory for a {@link ClassReader} that does not apply a class file version check if the
28
 * {@code net.bytebuddy.experimental} property is set.
29
 */
30
public class OpenedClassReader implements AsmClassReader.Factory {
×
31

32
    /**
33
     * Indicates that Byte Buddy should not validate the maximum supported class file version.
34
     */
35
    public static final String EXPERIMENTAL_PROPERTY = "net.bytebuddy.experimental";
36

37
    /**
38
     * Indicates what processor Byte Buddy is supposed to use if no processor is configured explicitly.
39
     */
40
    public static final String PROCESSOR_PROPERTY = "net.bytebuddy.processor";
41

42
    /**
43
     * {@code true} if Byte Buddy is executed in experimental mode.
44
     */
45
    public static final boolean EXPERIMENTAL;
46

47
    /**
48
     * Indicates the ASM API version that is used throughout Byte Buddy.
49
     */
50
    public static final int ASM_API;
51

52
    /*
53
     * Checks the experimental property.
54
     */
55
    static {
56
        boolean experimental;
57
        try {
58
            experimental = Boolean.parseBoolean(doPrivileged(new GetSystemPropertyAction(EXPERIMENTAL_PROPERTY)));
1✔
UNCOV
59
        } catch (Exception ignored) {
×
UNCOV
60
            experimental = false;
×
61
        }
1✔
62
        EXPERIMENTAL = experimental;
1✔
63
        ASM_API = Opcodes.ASM9;
1✔
64
    }
1✔
65

66
    /**
67
     * {@inheritDoc}
68
     */
69
    public AsmClassReader make(byte[] binaryRepresentation) {
UNCOV
70
        return new AsmClassReader.ForAsm(of(binaryRepresentation));
×
71
    }
72

73
    /**
74
     * {@inheritDoc}
75
     */
76
    public AsmClassReader make(byte[] binaryRepresentation, boolean experimental) {
UNCOV
77
        return new AsmClassReader.ForAsm(of(binaryRepresentation, experimental));
×
78
    }
79

80
    /**
81
     * A proxy for {@code java.security.AccessController#doPrivileged} that is activated if available.
82
     *
83
     * @param action The action to execute from a privileged context.
84
     * @param <T>    The type of the action's resolved value.
85
     * @return The action's resolved value.
86
     */
87
    @AccessControllerPlugin.Enhance
88
    private static <T> T doPrivileged(PrivilegedAction<T> action) {
UNCOV
89
        return action.run();
×
90
    }
91

92

93
    /**
94
     * Creates a class reader for the given binary representation of a class file.
95
     *
96
     * @param binaryRepresentation The binary representation of a class file to read.
97
     * @return An appropriate class reader.
98
     */
99
    public static ClassReader of(byte[] binaryRepresentation) {
UNCOV
100
        return of(binaryRepresentation, EXPERIMENTAL);
×
101
    }
102

103
    /**
104
     * Creates a class reader for the given binary representation of a class file.
105
     *
106
     * @param binaryRepresentation The binary representation of a class file to read.
107
     * @param experimental         {@code true} if unknown class file versions should also be processed.
108
     * @return An appropriate class reader.
109
     */
110
    public static ClassReader of(byte[] binaryRepresentation, boolean experimental) {
111
        ClassFileVersion classFileVersion = ClassFileVersion.ofClassFile(binaryRepresentation), latest = ClassFileVersion.latest();
1✔
112
        if (classFileVersion.isGreaterThan(latest)) {
1✔
113
            if (experimental) {
×
114
                binaryRepresentation[4] = (byte) (latest.getMinorVersion() >>> 8);
×
115
                binaryRepresentation[5] = (byte) latest.getMinorVersion();
×
116
                binaryRepresentation[6] = (byte) (latest.getMajorVersion() >>> 8);
×
117
                binaryRepresentation[7] = (byte) latest.getMajorVersion();
×
118
                ClassReader classReader = new ClassReader(binaryRepresentation);
×
UNCOV
119
                binaryRepresentation[4] = (byte) (classFileVersion.getMinorVersion() >>> 8);
×
120
                binaryRepresentation[5] = (byte) classFileVersion.getMinorVersion();
×
UNCOV
121
                binaryRepresentation[6] = (byte) (classFileVersion.getMajorVersion() >>> 8);
×
UNCOV
122
                binaryRepresentation[7] = (byte) classFileVersion.getMajorVersion();
×
UNCOV
123
                return classReader;
×
124
            } else {
UNCOV
125
                throw new IllegalArgumentException(classFileVersion
×
126
                        + " is not supported by the current version of Byte Buddy which officially supports " + latest
127
                        + " - update Byte Buddy or set " + EXPERIMENTAL_PROPERTY + " as a VM property");
128
            }
129
        } else {
130
            return new ClassReader(binaryRepresentation);
1✔
131
        }
132
    }
133
}
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