schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.6k stars 199 forks source link

IndexOutOfBoundsException for foreign key #71

Closed eoinsha closed 8 years ago

eoinsha commented 8 years ago

I came across this exception when crawling a database to generate a graph using 14.08.01-main.

SEVERE: Index: 0, Size: 0
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at schemacrawler.utility.MetaDataUtility.isForeignKeyUnique(MetaDataUtility.java:174)
    at schemacrawler.utility.MetaDataUtility.findForeignKeyCardinality(MetaDataUtility.java:132)
    at schemacrawler.tools.text.schema.SchemaDotFormatter.printForeignKeys(SchemaDotFormatter.java:377)
    at schemacrawler.tools.text.schema.SchemaDotFormatter.printForeignKeys(SchemaDotFormatter.java:369)
    at schemacrawler.tools.text.schema.SchemaDotFormatter.handle(SchemaDotFormatter.java:192)
    at schemacrawler.tools.traversal.SchemaTraverser.traverse(SchemaTraverser.java:129)
    at schemacrawler.tools.integration.graph.GraphExecutable.executeOn(GraphExecutable.java:124)
    at schemacrawler.tools.executable.SchemaCrawlerExecutable.executeOn(SchemaCrawlerExecutable.java:118)
    at schemacrawler.tools.executable.BaseStagedExecutable.execute(BaseStagedExecutable.java:94)
    at schemacrawler.tools.commandline.SchemaCrawlerCommandLine.execute(SchemaCrawlerCommandLine.java:133)
at schemacrawler.Main.main(Main.java:88)

It's SQL Server using the jTDS driver. The culprit in this case was a PK column which is a FK referencing itself (apparently this is possible!).

schemacrawler commented 8 years ago

Thanks. I will explore allowing this to be displayed on a diagram, and then create a lint to check for it.

schemacrawler commented 8 years ago

I have released SchemaCrawler 14.08.04 with a fix that supports self-referencing foreign keys in database diagrams.