JavaWebStack / JavaWebStack/orm

Show better error message when Model class isn't abstract

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
7
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Describe the Bug
When you extend the ORM Model to your own Model and forget to set it to abstract, you get an Exception saying

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Field.getType()" because the return value of "org.javawebstack.orm.TableInfo.getField(String)" is null
	at org.javawebstack.orm.TableInfo.getIdType(TableInfo.java:282)
	at org.javawebstack.orm.TableInfo.analyzeTable(TableInfo.java:95)
	at org.javawebstack.orm.TableInfo.constructInfo(TableInfo.java:61)
	at org.javawebstack.orm.TableInfo.<init>(TableInfo.java:56)
	at org.javawebstack.orm.Repo.<init>(Repo.java:35)
	at org.javawebstack.orm.ORM.register(ORM.java:25)
	at org.javawebstack.orm.ORM.register(ORM.java:37)

To Reproduce
Steps to reproduce the behavior:

  1. Forget to set your model class to abstract

Expected behavior
Maybe show some better error message which indicates that your base model isn't abstract yet.

Environment Information:

  • Java Language Level 21
  • ORM Version 1.0.3-SNAPSHOT

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by registering a non-abstract model, then start at ORM.register and follow the stack into Repo.java and TableInfo.java, especially constructInfo, analyzeTable, and getIdType around the reported lines. Check the existing model validation and error-handling paths. Done means this misuse produces a clear exception identifying that the base model must be abstract instead of the reported NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.