vdmeer / asciitable

Several implementations of a text table, originally using ASCII and UTF-8 characters for borders.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Null value at the last column cause exception

andy176631 opened this issue · comments

When I try the code:

final AsciiTable at = new AsciiTable();   
at.addRule();		
at.addRow("c_1_1", "c_1_2", "c_1_3");	
at.addRule();		
at.addRow("c_2_1", null, "c_2_3");		
at.addRule();
at.setTextAlignment(TextAlignment.CENTER);	
System.out.println(at.render());

The column spans as expected:

┌──────────────────────────┬─────────────────────────┬─────────────────────────┐
│          c_1_1           │          c_1_2          │          c_1_3          │
├──────────────────────────┼─────────────────────────┴─────────────────────────┤
│          c_2_1           │                       c_2_3                       │
└──────────────────────────┴───────────────────────────────────────────────────┘

But when the null value is at the last column:

final AsciiTable at = new AsciiTable();   
at.addRule();		
at.addRow("c_1_1", "c_1_2", "c_1_3");	
at.addRule();		
at1.addRow("c_2_1", "c_2_2", null);		
at.addRule();
at.setTextAlignment(TextAlignment.CENTER);	
System.out.println(at.render());

It cause exception as bellow:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 55, Size: 55
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at de.vandermeer.asciithemes.TA_GridHelpers.adjustBorder(TA_GridHelpers.java:194)
	at de.vandermeer.asciithemes.TA_Grid.addGrid(TA_Grid.java:306)
	at de.vandermeer.asciitable.AT_Renderer.renderAsCollection(AT_Renderer.java:282)
	at de.vandermeer.asciitable.AT_Renderer.render(AT_Renderer.java:128)
	at de.vandermeer.asciitable.AT_Renderer.render(AT_Renderer.java:112)
	at de.vandermeer.asciitable.AsciiTable.render(AsciiTable.java:185)
	at test.Test.main(Test.java:56)

I think this's one corner case that not been discovered