@@ -90,12 +90,12 @@ public class ClassEntry extends StructureTypeEntry {
9090 * A list of all files referenced from info associated with this class, including info detailing
9191 * inline method ranges.
9292 */
93- private ArrayList <FileEntry > files ;
93+ private final ArrayList <FileEntry > files ;
9494 /**
9595 * A list of all directories referenced from info associated with this class, including info
9696 * detailing inline method ranges.
9797 */
98- private ArrayList <DirEntry > dirs ;
98+ private final ArrayList <DirEntry > dirs ;
9999 /**
100100 * An index identifying the file table position of every file referenced from info associated
101101 * with this class, including info detailing inline method ranges.
@@ -113,8 +113,9 @@ public ClassEntry(String className, FileEntry fileEntry, int size) {
113113 this .loader = null ;
114114 // file and dir lists/indexes are populated after all DebugInfo API input has
115115 // been received and are only created on demand
116- files = null ;
117- dirs = null ;
116+ files = new ArrayList <>();
117+ dirs = new ArrayList <>();
118+ // create these on demand using the size of the file and dir lists
118119 this .fileIndex = null ;
119120 this .dirIndex = null ;
120121 }
@@ -375,9 +376,6 @@ public int hipc() {
375376 * @param file The file to be added.
376377 */
377378 public void includeFile (FileEntry file ) {
378- if (files == null ) {
379- files = new ArrayList <>();
380- }
381379 assert !files .contains (file ) : "caller should ensure file is only included once" ;
382380 assert fileIndex == null : "cannot include files after index has been created" ;
383381 files .add (file );
@@ -389,9 +387,6 @@ public void includeFile(FileEntry file) {
389387 * @param dirEntry The directory to be added.
390388 */
391389 public void includeDir (DirEntry dirEntry ) {
392- if (dirs == null ) {
393- dirs = new ArrayList <>();
394- }
395390 assert !dirs .contains (dirEntry ) : "caller should ensure dir is only included once" ;
396391 assert dirIndex == null : "cannot include dirs after index has been created" ;
397392 dirs .add (dirEntry );
@@ -404,18 +399,14 @@ public void includeDir(DirEntry dirEntry) {
404399 public void buildFileAndDirIndexes () {
405400 // this is a one-off operation
406401 assert fileIndex == null && dirIndex == null : "file and indexes can only be generated once" ;
407- if (files == null ) {
408- assert dirs == null : "should not have included any dirs if we have no files" ;
409- return ;
402+ if (files .isEmpty ()) {
403+ assert dirs .isEmpty () : "should not have included any dirs if we have no files" ;
410404 }
411405 int idx = 1 ;
412406 fileIndex = EconomicMap .create (files .size ());
413407 for (FileEntry file : files ) {
414408 fileIndex .put (file , idx ++);
415409 }
416- if (dirs == null ) {
417- return ;
418- }
419410 dirIndex = EconomicMap .create (dirs .size ());
420411 idx = 1 ;
421412 for (DirEntry dir : dirs ) {
@@ -434,7 +425,7 @@ public void buildFileAndDirIndexes() {
434425 * @return a stream of all referenced files
435426 */
436427 public Stream <FileEntry > fileStream () {
437- if (files != null ) {
428+ if (! files . isEmpty () ) {
438429 return files .stream ();
439430 } else {
440431 return Stream .empty ();
@@ -448,7 +439,7 @@ public Stream<FileEntry> fileStream() {
448439 * @return a stream of all referenced directories
449440 */
450441 public Stream <DirEntry > dirStream () {
451- if (dirs != null ) {
442+ if (! dirs . isEmpty () ) {
452443 return dirs .stream ();
453444 } else {
454445 return Stream .empty ();
0 commit comments