11/*
2- * Copyright (C) 2025 The MegaMek Team. All Rights Reserved.
2+ * Copyright (C) 2025-2026 The MegaMek Team. All Rights Reserved.
33 *
44 * This file is part of MegaMek.
55 *
@@ -141,11 +141,16 @@ public boolean isEmpty() {
141141 return data .isEmpty ();
142142 }
143143
144+ private int colWidth (int col ) {
145+ // the colWidth map does not always have values for each column of colNames, therefore use a safe getter:
146+ return colWidth .getOrDefault (col , 0 );
147+ }
148+
144149 @ Override
145150 public String toPlainText () {
146151 StringBuilder sb = new StringBuilder ();
147152 for (int col = 0 ; col < colNames .length ; col ++) {
148- sb .append (justify (justification [col ], colNames [col ], colWidth . get (col )));
153+ sb .append (justify (justification [col ], colNames [col ], colWidth (col )));
149154 sb .append (PLAIN_COL_PADDING );
150155 }
151156 sb .append ("\n " );
@@ -155,7 +160,7 @@ public String toPlainText() {
155160 }
156161 for (ViewElement [] row : data ) {
157162 for (int col = 0 ; col < row .length ; col ++) {
158- sb .append (justify (justification [col ], row [col ].toPlainText (), colWidth . get (col )));
163+ sb .append (justify (justification [col ], row [col ].toPlainText (), colWidth (col )));
159164 sb .append (PLAIN_COL_PADDING );
160165 }
161166 sb .append ("\n " );
@@ -199,7 +204,7 @@ public String toDiscord() {
199204 StringBuilder sb = new StringBuilder ();
200205 sb .append (DiscordFormat .UNDERLINE ).append (DiscordFormat .ROW_SHADING );
201206 for (int col = 0 ; col < colNames .length ; col ++) {
202- sb .append (justify (justification [col ], colNames [col ], colWidth . get (col )));
207+ sb .append (justify (justification [col ], colNames [col ], colWidth (col )));
203208 if (col < colNames .length - 1 ) {
204209 sb .append (PLAIN_COL_PADDING );
205210 }
@@ -212,7 +217,7 @@ public String toDiscord() {
212217 }
213218 for (int col = 0 ; col < row .length ; col ++) {
214219 sb .append (DiscordFormat .highlightNumbersForDiscord (justify (justification [col ],
215- row [col ].toPlainText (), colWidth . get (col ))));
220+ row [col ].toPlainText (), colWidth (col ))));
216221 if (col < row .length - 1 ) {
217222 sb .append (PLAIN_COL_PADDING );
218223 }
0 commit comments