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

TextTitle throws a different exception from other related classes #205

Closed
tohidemyname opened this issue Jan 20, 2021 · 3 comments
Closed

Comments

@tohidemyname
Copy link

TextTitle throws NullPointerException fo rnull parameters:
` public TextTitle(String text, Font font, Paint paint,
RectangleEdge position,
HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment,
RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);

    if (text == null) {
        throw new NullPointerException("Null 'text' argument.");
    }
    if (font == null) {
        throw new NullPointerException("Null 'font' argument.");
    }
    if (paint == null) {
        throw new NullPointerException("Null 'paint' argument.");
    }
    this.text = text;
    this.font = font;
    this.paint = paint;
    // the textAlignment and the horizontalAlignment are separate things,
    // but it makes sense for the default textAlignment to match the
    // title's horizontal alignment...
    this.textAlignment = horizontalAlignment;
    this.backgroundPaint = null;
    this.content = null;
    this.toolTipText = null;
    this.urlText = null;

}`

Other classes throw IllegalArgumentException. For example:

public TextLine(String text, Font font, Paint paint) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument."); } if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.fragments = new java.util.ArrayList<>(); final TextFragment fragment = new TextFragment(text, font, paint); this.fragments.add(fragment); }

Another example:

public TextFragment(String text, Font font, Paint paint, float baselineOffset) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument."); } if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.text = text; this.font = font; this.paint = paint; this.baselineOffset = baselineOffset; }

@trashgod
Copy link
Contributor

For reference,

As an aside, I see the master branch moving towards Objects.requireNonNull, which "throws a customized NullPointerException."

@jfree
Copy link
Owner

jfree commented Jan 21, 2021

For a short while, I decided moving to Objects.requireNonNull was a good idea because it's the Java standard approach. However, I came back to my original thinking that IllegalArgumentException is more correct, so I intend to switch back to that. The link you posted is excellent, I hadn't seen that before.

@jfree
Copy link
Owner

jfree commented Jan 21, 2021

Fixed on the master branch.

@jfree jfree closed this as completed Jan 21, 2021
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

3 participants