Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminating null reference error when generating HTML for Constraints MSSQL #1422

Open
kylefossum opened this issue Mar 21, 2024 · 1 comment

Comments

@kylefossum
Copy link

kylefossum commented Mar 21, 2024

Greetings, when using the latest release of Schema Spy, 6.2.4, this line throws a big ugly stack trace when trying to create the HTML output due to trying to trim a null reference.

I updated and compiled a jar locally after changing that line to entry.getValue() == null ? "" : entry.getValue().trim()) and everything was peachy. Seems like a fairly quick and harmless fix, or at least it did the trick for me.

I'm by no means a database or Java expert, but evidently it's possible when using Microsoft SQL (Azure SQL) to have a null value returned for that property. Can't speak to much beyond the fact that that is true of our production database unfortunately.

Expected Behavior

Schema Spy gracefully handles null values returned for that property.

Current Behavior

Terminating error, causing partial rendering of the images and web assets.

.....Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.NullPointerException: Cannot invoke "String.trim()" because the return value of "java.util.Map$Entry.getValue()" is null
        at org.schemaspy.view.HtmlConstraintsPage.lambda$collectCheckConstraints$1(HtmlConstraintsPage.java:83)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
        at java.base/java.util.TreeMap$EntrySpliterator.forEachRemaining(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline$7$1.accept(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
        at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
        at java.base/java.util.stream.ReferencePipeline.collect(Unknown Source)
        at org.schemaspy.view.HtmlConstraintsPage.collectCheckConstraints(HtmlConstraintsPage.java:85)
        at org.schemaspy.view.HtmlConstraintsPage.write(HtmlConstraintsPage.java:64)
        at org.schemaspy.SchemaAnalyzer.generateHtmlDoc(SchemaAnalyzer.java:443)
        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:289)
        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:135)
        at org.schemaspy.cli.SchemaSpyRunner.runAnalyzer(SchemaSpyRunner.java:109)
        at org.schemaspy.cli.SchemaSpyRunner.run(SchemaSpyRunner.java:98)
        at org.schemaspy.Main.main(Main.java:55)
        ... 6 more

Possible Solution

Some logic to only call trim() if the object isn't null. entry.getValue() == null ? "" : entry.getValue().trim()) worked for my use case.

Steps to Reproduce (for bugs)

I'm going to do a bad job filling this out :(. If really necessary I can provide a Docker compose file that will likely reproduce the problem, but I'd have to dig for a bit to figure out what in the db is causing a null value to be returned.

Happy to do so if necessary, but I think this might be simple enough that that's overkill. Please do let me know.

Context

Use Schema Spy against MS SQL

  • Microsoft SQL (Azure)
  • mssql-jdbc JRE 11 (latest)
  • Your DDL (sample how to reproduce the issue):
  • Full command including arguments how you run SchemaSpy:
  • schemaspy.jar -t "mssql17" -db "test" -dp "lib/mssql17-jdbc.jar" -s "dbo" -u "test" -p "test" -host "test.database.windows.net" -o /var/www/html -hq -vizjs

Your Environment

  • Version used: 6.2.4
  • eclipse-temurin:21-jre-alpine as a base Docker image
@npetzall
Copy link
Member

Hi,

It's the following query
select OBJECT_NAME(parent_object_id) as table_name, name AS constraint_name, definition as text from sys.check_constraints

That returns null for the text alias of definition in sys.check_constraints

Are you able to run the query as well as just list columns in sys.check_constraints. I wonder if they might have changed the column name or something like that. Since it would be strange from a db perspective to have a check constraints thats missing the check definition.

There might be a scenario that I'll look into if they have any secondary columns that defines a function or something like that.

If the table is empty we are creating an empty entry when nothing should be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants