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

Scalar handlers might return null #4

Closed
io7m opened this issue Feb 6, 2021 · 0 comments
Closed

Scalar handlers might return null #4

io7m opened this issue Feb 6, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@io7m
Copy link
Owner

io7m commented Feb 6, 2021

The following scalar handler:

public final class BTScalarElementHandler<S> implements BTElementHandlerType<Object, S>
{
  private final BTCharacterHandlerType<S> handler;
  private final BTQualifiedName name;
  private S result;

  /**
   * Construct a handler.
   *
   * @param inName    The name of elements handled by this handler
   * @param inHandler The character handler
   */

  public BTScalarElementHandler(
    final BTQualifiedName inName,
    final BTCharacterHandlerType<S> inHandler)
  {
    this.name = Objects.requireNonNull(inName, "name");
    this.handler = Objects.requireNonNull(inHandler, "handler");
  }

  @Override
  public String name()
  {
    return this.name.localName();
  }

  @Override
  public void onCharacters(
    final BTElementParsingContextType context,
    final char[] data,
    final int offset,
    final int length)
    throws Exception
  {
    this.result = this.handler.parse(context, data, offset, length);
  }

  @Override
  public S onElementFinished(
    final BTElementParsingContextType context)
  {
    return this.result;
  }
}

... Might return null. The reason: A closed element such as <element/> will cause the onCharacters method not to be called, resulting in this.result being unassigned.

@io7m io7m added the bug Something isn't working label Feb 6, 2021
@io7m io7m self-assigned this Feb 6, 2021
@io7m io7m closed this as completed in 2c73f9e Feb 6, 2021
io7m added a commit that referenced this issue Feb 6, 2021
Change: Ensure that scalar element handlers never return null for empty elements (Ticket: #4)
io7m added a commit that referenced this issue Feb 6, 2021
Release: com.io7m.blackthorne 1.2.1
Change: Ensure that scalar element handlers never return null for empty elements (Ticket: #4)
io7m added a commit that referenced this issue Feb 6, 2021
Release: com.io7m.blackthorne 1.2.1

Change: Ensure that scalar element handlers never return null for empty elements (Ticket: #4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant