Skip to content
Permalink
Browse files
Use Objects.requireNonNull()
  • Loading branch information
garydgregory committed May 6, 2022
1 parent 74fef2a commit 8e6faf4bf75ac16c011606bb592af5544c71ab49
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
@@ -18,6 +18,7 @@

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;

/**
* Constant pool entry for a class
@@ -39,10 +40,7 @@ public class CPClass extends ConstantPoolEntry {
*/
public CPClass(final CPUTF8 name, final int globalIndex) {
super(ConstantPoolEntry.CP_Class, globalIndex);
if (name == null) {
throw new NullPointerException("Null arguments are not allowed");
}
this.name = name.underlyingString();
this.name = Objects.requireNonNull(name, "name").underlyingString();
this.utf8 = name;
}

@@ -16,6 +16,8 @@
*/
package org.apache.commons.compress.harmony.unpack200.bytecode;

import java.util.Objects;

/**
* Abstract superclass for constant pool constant entries such as numbers or Strings
*/
@@ -33,10 +35,7 @@ public abstract class CPConstant extends ConstantPoolEntry {
*/
public CPConstant(final byte tag, final Object value, final int globalIndex) {
super(tag, globalIndex);
this.value = value;
if (value == null) {
throw new NullPointerException("Null arguments are not allowed");
}
this.value = Objects.requireNonNull(value, "value");
}

@Override
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Superclass for member constant pool entries, such as fields or methods.
@@ -43,13 +44,10 @@ public class CPMember extends ClassFileEntry {
* @throws NullPointerException if name or descriptor is null
*/
public CPMember(final CPUTF8 name, final CPUTF8 descriptor, final long flags, final List attributes) {
this.name = name;
this.descriptor = descriptor;
this.name = Objects.requireNonNull(name, "name");
this.descriptor = Objects.requireNonNull(descriptor, "descriptor");
this.flags = (short) flags;
this.attributes = attributes == null ? Collections.EMPTY_LIST : attributes;
if (name == null || descriptor == null) {
throw new NullPointerException("Null arguments are not allowed");
}
}

@Override
@@ -18,6 +18,7 @@

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;

import org.apache.commons.compress.harmony.unpack200.SegmentUtils;

@@ -44,11 +45,8 @@ public class CPNameAndType extends ConstantPoolEntry {
*/
public CPNameAndType(final CPUTF8 name, final CPUTF8 descriptor, final int globalIndex) {
super(ConstantPoolEntry.CP_NameAndType, globalIndex);
this.name = name;
this.descriptor = descriptor;
if (name == null || descriptor == null) {
throw new NullPointerException("Null arguments are not allowed");
}
this.name = Objects.requireNonNull(name, "name");
this.descriptor = Objects.requireNonNull(descriptor, "descriptor");
}

@Override
@@ -18,6 +18,7 @@

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;

/**
* Abstract superclass for reference constant pool entries, such as a method or field reference.
@@ -41,11 +42,8 @@ public abstract class CPRef extends ConstantPoolEntry {
*/
public CPRef(final byte type, final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
super(type, globalIndex);
this.className = className;
this.nameAndType = descriptor;
if (descriptor == null || className == null) {
throw new NullPointerException("Null arguments are not allowed");
}
this.className = Objects.requireNonNull(className, "className");
this.nameAndType = Objects.requireNonNull(descriptor, "descriptor");
}

@Override
@@ -18,6 +18,7 @@

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Objects;

/**
* UTF8 constant pool entry, used for storing long Strings.
@@ -35,10 +36,7 @@ public class CPUTF8 extends ConstantPoolEntry {
*/
public CPUTF8(final String utf8, final int globalIndex) {
super(ConstantPoolEntry.CP_UTF8, globalIndex);
this.utf8 = utf8;
if (utf8 == null) {
throw new NullPointerException("Null arguments are not allowed");
}
this.utf8 = Objects.requireNonNull(utf8, "utf8");
}

public CPUTF8(final String string) {
@@ -16,6 +16,8 @@
*/
package org.apache.commons.compress.harmony.unpack200.bytecode.forms;

import java.util.Objects;

import org.apache.commons.compress.harmony.pack200.Pack200Exception;
import org.apache.commons.compress.harmony.unpack200.SegmentConstantPool;
import org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode;
@@ -40,9 +42,7 @@ protected void setNestedEntries(final ByteCode byteCode, final OperandManager op
final SegmentConstantPool globalPool = operandManager.globalConstantPool();
ClassFileEntry[] nested = null;
nested = new ClassFileEntry[] {globalPool.getConstantPoolEntry(getPoolID(), offset)};
if (nested[0] == null) {
throw new NullPointerException("Null nested entries are not allowed");
}
Objects.requireNonNull(nested[0], "Null nested entries are not allowed");
byteCode.setNested(nested);
byteCode.setNestedPositions(new int[][] {{0, 2}});
}

0 comments on commit 8e6faf4

Please sign in to comment.