diff options
author | Liam Miller-Cushon <cushon@google.com> | 2021-07-21 16:40:49 -0700 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2021-07-21 16:41:32 -0700 |
commit | 3fe0e713f32ecd7f436894d5d4f83e1ea36192f6 (patch) | |
tree | f1334c7de28099e6a59b48eb87d0a5febd791b88 /java | |
parent | ecea03305c29df5de7a3fa8ccb903fc07b530ec0 (diff) | |
download | turbine-3fe0e713f32ecd7f436894d5d4f83e1ea36192f6.tar.gz |
Annotate bytecode packages for nullness
PiperOrigin-RevId: 386122520
Diffstat (limited to 'java')
5 files changed, 34 insertions, 32 deletions
diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java index d2383b6..af8a8a3 100644 --- a/java/com/google/turbine/binder/bytecode/BytecodeBinder.java +++ b/java/com/google/turbine/binder/bytecode/BytecodeBinder.java @@ -16,6 +16,8 @@ package com.google.turbine.binder.bytecode; +import static java.util.Objects.requireNonNull; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.turbine.binder.bound.EnumConstantValue; @@ -206,6 +208,7 @@ public final class BytecodeBinder { public static ModuleInfo bindModuleInfo(String path, Supplier<byte[]> bytes) { ClassFile classFile = ClassReader.read(path, bytes.get()); ClassFile.ModuleInfo module = classFile.module(); + requireNonNull(module, path); return new ModuleInfo( module.name(), module.version(), diff --git a/java/com/google/turbine/bytecode/ClassFile.java b/java/com/google/turbine/bytecode/ClassFile.java index e979edc..141c145 100644 --- a/java/com/google/turbine/bytecode/ClassFile.java +++ b/java/com/google/turbine/bytecode/ClassFile.java @@ -33,22 +33,22 @@ public class ClassFile { private final int access; private final String name; - private final String signature; - private final String superClass; + private final @Nullable String signature; + private final @Nullable String superClass; private final List<String> interfaces; private final List<MethodInfo> methods; private final List<FieldInfo> fields; private final List<AnnotationInfo> annotations; private final List<InnerClass> innerClasses; private final ImmutableList<TypeAnnotationInfo> typeAnnotations; - @Nullable private final ModuleInfo module; - @Nullable private final String transitiveJar; + private final @Nullable ModuleInfo module; + private final @Nullable String transitiveJar; public ClassFile( int access, String name, - String signature, - String superClass, + @Nullable String signature, + @Nullable String superClass, List<String> interfaces, List<MethodInfo> methods, List<FieldInfo> fields, @@ -82,12 +82,12 @@ public class ClassFile { } /** The value of the Signature attribute. */ - public String signature() { + public @Nullable String signature() { return signature; } /** The super class. */ - public String superName() { + public @Nullable String superName() { return superClass; } @@ -139,8 +139,8 @@ public class ClassFile { private final int access; private final String name; private final String descriptor; - @Nullable private final String signature; - private final Const.@Nullable Value value; + private final @Nullable String signature; + private final @Nullable Value value; private final List<AnnotationInfo> annotations; private final ImmutableList<TypeAnnotationInfo> typeAnnotations; @@ -149,7 +149,7 @@ public class ClassFile { String name, String descriptor, @Nullable String signature, - Value value, + @Nullable Value value, List<AnnotationInfo> annotations, ImmutableList<TypeAnnotationInfo> typeAnnotations) { this.access = access; @@ -730,16 +730,16 @@ public class ClassFile { } } - private final TypePath parent; - private final TypePath.Kind kind; + private final @Nullable TypePath parent; + private final TypePath.@Nullable Kind kind; private final int index; - private TypePath(TypePath.Kind kind, TypePath parent) { + private TypePath(TypePath.@Nullable Kind kind, @Nullable TypePath parent) { // JVMS 4.7.20.2: type_argument_index is 0 if the bound kind is not TYPE_ARGUMENT this(0, kind, parent); } - private TypePath(int index, TypePath.Kind kind, TypePath parent) { + private TypePath(int index, TypePath.@Nullable Kind kind, @Nullable TypePath parent) { this.index = index; this.kind = kind; this.parent = parent; @@ -752,13 +752,13 @@ public class ClassFile { /** The JVMS 4.7.20.2-A serialized value of the type_path_kind. */ public byte tag() { - return (byte) kind.tag; + return (byte) requireNonNull(kind).tag; } /** Returns a flattened view of the type path. */ public ImmutableList<TypePath> flatten() { Deque<TypePath> flat = new ArrayDeque<>(); - for (TypePath curr = this; curr.kind != null; curr = curr.parent) { + for (TypePath curr = this; requireNonNull(curr).kind != null; curr = curr.parent) { flat.addFirst(curr); } return ImmutableList.copyOf(flat); @@ -770,7 +770,7 @@ public class ClassFile { public static class ModuleInfo { private final String name; - private final String version; + private final @Nullable String version; private final int flags; private final ImmutableList<RequireInfo> requires; private final ImmutableList<ExportInfo> exports; @@ -781,7 +781,7 @@ public class ClassFile { public ModuleInfo( String name, int flags, - String version, + @Nullable String version, ImmutableList<RequireInfo> requires, ImmutableList<ExportInfo> exports, ImmutableList<OpenInfo> opens, @@ -805,7 +805,7 @@ public class ClassFile { return flags; } - public String version() { + public @Nullable String version() { return version; } @@ -834,9 +834,9 @@ public class ClassFile { private final String moduleName; private final int flags; - private final String version; + private final @Nullable String version; - public RequireInfo(String moduleName, int flags, String version) { + public RequireInfo(String moduleName, int flags, @Nullable String version) { this.moduleName = moduleName; this.flags = flags; this.version = version; @@ -850,7 +850,7 @@ public class ClassFile { return flags; } - public String version() { + public @Nullable String version() { return version; } } diff --git a/java/com/google/turbine/bytecode/ClassReader.java b/java/com/google/turbine/bytecode/ClassReader.java index cb72d3e..5022ff7 100644 --- a/java/com/google/turbine/bytecode/ClassReader.java +++ b/java/com/google/turbine/bytecode/ClassReader.java @@ -16,6 +16,8 @@ package com.google.turbine.bytecode; +import static java.util.Objects.requireNonNull; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.errorprone.annotations.CheckReturnValue; @@ -173,6 +175,7 @@ public class ClassReader { String innerName = innerNameIndex != 0 ? constantPool.utf8(innerNameIndex) : null; int innerClassAccessFlags = reader.u2(); if (innerName != null && (thisClass.equals(innerClass) || thisClass.equals(outerClass))) { + requireNonNull(outerClass); innerclasses.add( new ClassFile.InnerClass(innerClass, outerClass, innerName, innerClassAccessFlags)); } diff --git a/java/com/google/turbine/bytecode/sig/Sig.java b/java/com/google/turbine/bytecode/sig/Sig.java index f759269..2e4f154 100644 --- a/java/com/google/turbine/bytecode/sig/Sig.java +++ b/java/com/google/turbine/bytecode/sig/Sig.java @@ -59,18 +59,18 @@ public final class Sig { public static class TyParamSig { private final String name; - @Nullable private final TySig classBound; + private final @Nullable TySig classBound; private final ImmutableList<TySig> interfaceBounds; - public TyParamSig(String name, TySig classBound, ImmutableList<TySig> interfaceBounds) { + public TyParamSig( + String name, @Nullable TySig classBound, ImmutableList<TySig> interfaceBounds) { this.name = name; this.classBound = classBound; this.interfaceBounds = interfaceBounds; } /** A single class upper-bound, or {@code null}. */ - @Nullable - public TySig classBound() { + public @Nullable TySig classBound() { return classBound; } diff --git a/java/com/google/turbine/lower/LowerSignature.java b/java/com/google/turbine/lower/LowerSignature.java index c773a09..eb35dc7 100644 --- a/java/com/google/turbine/lower/LowerSignature.java +++ b/java/com/google/turbine/lower/LowerSignature.java @@ -199,11 +199,7 @@ public class LowerSignature { return null; } ImmutableList<Sig.TyParamSig> typarams = tyParamSig(info.typeParameterTypes(), env); - - ClassTySig xtnd = null; - if (info.superClassType() != null) { - xtnd = classTySig((ClassTy) info.superClassType()); - } + ClassTySig xtnd = classTySig((ClassTy) info.superClassType()); ImmutableList.Builder<ClassTySig> impl = ImmutableList.builder(); for (Type i : info.interfaceTypes()) { impl.add(classTySig((ClassTy) i)); |