< prev index next >

src/java.base/share/classes/jdk/internal/jimage/ImageLocation.java

Print this page
rev 14631 : 8156209: Add argument checks to BasicImageReader calls
Reviewed-by: sundar

@@ -24,10 +24,11 @@
  */
 
 package jdk.internal.jimage;
 
 import java.nio.ByteBuffer;
+import java.util.Objects;
 
 /**
  * @implNote This class needs to maintain JDK 8 source compatibility.
  *
  * It is used internally in the JDK to implement jimage/jrtfs access,

@@ -48,10 +49,12 @@
     protected final long[] attributes;
 
     protected final ImageStrings strings;
 
     public ImageLocation(long[] attributes, ImageStrings strings) {
+        Objects.requireNonNull(attributes);
+        Objects.requireNonNull(strings);
         this.attributes = attributes;
         this.strings = strings;
     }
 
     ImageStrings getStrings() {

@@ -65,10 +68,11 @@
     private static int attributeKind(int data) {
         return data >>> 3;
     }
 
     static long[] decompress(ByteBuffer bytes) {
+        Objects.requireNonNull(bytes);
         long[] attributes = new long[ATTRIBUTE_COUNT];
 
         if (bytes != null) {
             while (bytes.hasRemaining()) {
                 int data = bytes.get() & 0xFF;

@@ -101,10 +105,11 @@
 
         return attributes;
     }
 
     public static byte[] compress(long[] attributes) {
+        Objects.requireNonNull(attributes);
         ImageStream stream = new ImageStream(16);
 
         for (int kind = ATTRIBUTE_END + 1; kind < ATTRIBUTE_COUNT; kind++) {
             long value = attributes[kind];
 

@@ -122,10 +127,12 @@
 
         return stream.toArray();
      }
 
     public boolean verify(String name) {
+        Objects.requireNonNull(name);
+        
         return name.equals(getFullName());
     }
 
     long getAttribute(int kind) {
         if (kind < ATTRIBUTE_END || ATTRIBUTE_COUNT <= kind) {

@@ -248,10 +255,11 @@
     public long getUncompressedSize() {
         return getAttribute(ATTRIBUTE_UNCOMPRESSED);
     }
 
     static ImageLocation readFrom(BasicImageReader reader, int offset) {
+        Objects.requireNonNull(reader);
         long[] attributes = reader.getAttributes(offset);
         ImageStringsReader strings = reader.getStrings();
 
         return new ImageLocation(attributes, strings);
     }
< prev index next >