Skip to content

Commit b78f654

Browse files
committed
Initial support for Java 14
1 parent dd13fcf commit b78f654

File tree

10 files changed

+661
-10
lines changed

10 files changed

+661
-10
lines changed

build.xml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<equals arg1="${-cleaned.specification.version}" arg2="11"/>
6363
<equals arg1="${-cleaned.specification.version}" arg2="12"/>
6464
<equals arg1="${-cleaned.specification.version}" arg2="13"/>
65+
<equals arg1="${-cleaned.specification.version}" arg2="14"/>
6566
</or>
6667
</condition>
6768

ivy.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!DOCTYPE ivy-module [
1818
<!ENTITY maven.version "2.0">
1919
<!ENTITY gradle.version "2.3">
20-
<!ENTITY asm.version "7.2">
20+
<!ENTITY asm.version "8.0">
2121
<!ENTITY jarjar.asm.version "5.2">
2222
]>
2323
<ivy-module version="2.0">

src/main/docs/bundled-signatures.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ <h1>Bundled Signatures Documentation</h1>
2929
<li><strong><tt>jdk-unsafe-*</tt>:</strong> Signatures
3030
of &quot;unsafe&quot; methods that use default charset, default locale, or default timezone. For server applications it is very
3131
stupid to call those methods, as the results will definitely not what the user wants
32-
(for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13; Ant / Maven / Gradle automatically add the compile Java version).</li>
32+
(for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13, 14; Ant / Maven / Gradle automatically add the compile Java version).</li>
3333

3434
<li><strong><tt>jdk-deprecated-*</tt>:</strong> This disallows all deprecated
35-
methods from the JDK (for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13; Ant / Maven / Gradle automatically add the compile Java version).</li>
35+
methods from the JDK (for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13, 14; Ant / Maven / Gradle automatically add the compile Java version).</li>
3636

3737
<li><strong><tt>jdk-internal-*</tt>:</strong> Lists all internal packages of the JDK as of <code>Security.getProperty(&quot;package.access&quot;)</code>.
3838
Calling those methods will always trigger security manager and is completely forbidden from Java 9 on
39-
(for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13; Ant / Maven / Gradle automatically add the compile Java version, <em>since forbiddenapis v2.1</em>).</li>
39+
(for Java <tt>*</tt> = 1.6, 1.7, 1.8, 9, 10, 11, 12, 13, 14; Ant / Maven / Gradle automatically add the compile Java version, <em>since forbiddenapis v2.1</em>).</li>
4040

4141
<li><strong><tt>jdk-non-portable</tt>:</strong> Signatures of all non-portable (like <code>com.sun.management.HotSpotDiagnosticMXBean</code>)
4242
or internal runtime APIs (like <code>sun.misc.Unsafe</code>). This is a superset of <tt>jdk-internal</tt>.<br>

src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private static byte[] readStream(final InputStream in) throws IOException {
179179
@SuppressWarnings("unused")
180180
public static ClassReader readAndPatchClass(InputStream in) throws IOException {
181181
final byte[] bytecode = readStream(in);
182-
if (false) patchClassMajorVersion(bytecode, Opcodes.V10 + 1, Opcodes.V10);
182+
if (false) patchClassMajorVersion(bytecode, Opcodes.V15 + 1, Opcodes.V15);
183183
return new ClassReader(bytecode);
184184
}
185185

src/main/java/de/thetaphi/forbiddenapis/ClassScanner.java

+37-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.objectweb.asm.Label;
3636
import org.objectweb.asm.MethodVisitor;
3737
import org.objectweb.asm.Opcodes;
38+
import org.objectweb.asm.RecordComponentVisitor;
3839
import org.objectweb.asm.Type;
3940
import org.objectweb.asm.TypePath;
4041
import org.objectweb.asm.commons.Method;
@@ -63,7 +64,7 @@ public final class ClassScanner extends ClassVisitor implements Constants {
6364
boolean classSuppressed = false;
6465

6566
public ClassScanner(RelatedClassLookup lookup, Signatures forbiddenSignatures, final Pattern suppressAnnotations) {
66-
super(Opcodes.ASM7);
67+
super(Opcodes.ASM8);
6768
this.lookup = lookup;
6869
this.forbiddenSignatures = forbiddenSignatures;
6970
this.suppressAnnotations = suppressAnnotations;
@@ -249,7 +250,7 @@ public FieldVisitor visitField(final int access, final String name, final String
249250
if (classSuppressed) {
250251
return null;
251252
}
252-
return new FieldVisitor(Opcodes.ASM7) {
253+
return new FieldVisitor(Opcodes.ASM8) {
253254
final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0;
254255
{
255256
// only check signature, if field is not synthetic
@@ -294,7 +295,7 @@ public MethodVisitor visitMethod(final int access, final String name, final Stri
294295
if (classSuppressed) {
295296
return null;
296297
}
297-
return new MethodVisitor(Opcodes.ASM7) {
298+
return new MethodVisitor(Opcodes.ASM8) {
298299
private final Method myself = new Method(name, desc);
299300
private final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0;
300301
private int lineNo = -1;
@@ -531,6 +532,39 @@ public void visitLineNumber(int lineNo, Label start) {
531532
};
532533
}
533534

535+
@Override
536+
public RecordComponentVisitor visitRecordComponent(final String name, final String desc, final String signature) {
537+
currentGroupId++;
538+
if (classSuppressed) {
539+
return null;
540+
}
541+
return new RecordComponentVisitor(Opcodes.ASM8) {
542+
{
543+
reportRecordComponentViolation(checkDescriptor(desc), "record component declaration");
544+
}
545+
546+
@Override
547+
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
548+
final Type type = Type.getType(desc);
549+
maybeSuppressCurrentGroup(type);
550+
reportRecordComponentViolation(checkAnnotationDescriptor(type, visible), "annotation on record component declaration");
551+
return null;
552+
}
553+
554+
@Override
555+
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
556+
reportRecordComponentViolation(checkAnnotationDescriptor(Type.getType(desc), visible), "type annotation on record component declaration");
557+
return null;
558+
}
559+
560+
private void reportRecordComponentViolation(String violation, String where) {
561+
if (violation != null) {
562+
violations.add(new ForbiddenViolation(currentGroupId, violation, String.format(Locale.ENGLISH, "%s of '%s'", where, name), -1));
563+
}
564+
}
565+
};
566+
}
567+
534568
@Override
535569
public void visitEnd() {
536570
// fixup lambdas by assigning them the groupId where they were originally declared:

src/main/java/de/thetaphi/forbiddenapis/ClassSignature.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ClassSignature(final ClassReader classReader, boolean isRuntimeClass, boo
5252
final Set<Method> methods = new HashSet<Method>();
5353
final Set<String> fields = new HashSet<String>();
5454
final Set<String> signaturePolymorphicMethods = new HashSet<String>();
55-
classReader.accept(new ClassVisitor(Opcodes.ASM7) {
55+
classReader.accept(new ClassVisitor(Opcodes.ASM8) {
5656
@Override
5757
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
5858
final Method m = new Method(name, desc);

0 commit comments

Comments
 (0)