Skip to content

Support for empty symbols, e.g. ''#108

Merged
raganhan merged 3 commits intomasterfrom
support-empty-symbol-42
Jul 26, 2017
Merged

Support for empty symbols, e.g. ''#108
raganhan merged 3 commits intomasterfrom
support-empty-symbol-42

Conversation

@raganhan
Copy link
Copy Markdown
Contributor

Issue: #42

@raganhan raganhan requested review from a team and tgregg July 21, 2017 21:01
@toddjonker toddjonker self-requested a review July 21, 2017 22:22
@toddjonker
Copy link
Copy Markdown
Contributor

I definitely want to review this, hopefully this weekend. Stoked this is getting fixed!

Copy link
Copy Markdown
Contributor

@tgregg tgregg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • A few fixes requested in the tests.
  • Suggestion to factor the style-related changes (import order, variable renames) into a separate PR to make this one smaller and easier to review.
  • Other than that, the related fixes look good.

Comment thread src/software/amazon/ion/IonWriter.java Outdated

package software.amazon.ion;

import software.amazon.ion.system.IonTextWriterBuilder;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably best to configure your IDE so that it doesn't change the import order in this repo. It's bloating the size of the diff and has the potential to be reversed in a subsequent PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated the code style changes and fiddled a bit with my IDE settings to avoid this in the future.

Do we have a style guide I can use as reference?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity: the Eclipse preferences stored in .settings. We can store preferences for IntelliJ too if needed.

break;
case 'f':
if (valuelen == 5 // 'f'
if (valueLength == 5 // 'f'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the variable was renamed, the 'f' was in the same column as the 'alse' that follow. Please either fix that or leave the rename for a separate style-related PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated the code style changes

if (text == null || text.length() == 0)
if (text == null)
{
throw new EmptySymbolException();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be NPE or IllegalArgumentException. Then we can eliminate EmptySymbolException altogether.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this would be better as NPE or IAE. However I was avoiding removing EmptySymbolException whenever possible as it breaks binary compatibility for some interfaces, since EmptySymbolException is a checked exception.

I'm pro removing it as a whole if we consider are OK with this kind of compatibility break

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you determine the impact to be? Will the new code compile for users who explicitly check for EmptySymbolException?

fail("expected exception");
}
catch (EmptySymbolException e) { }
iw.writeSymbol("a");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't writing an empty symbol, as the name suggests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

throws Exception
{
iw = makeWriter();
iw.writeSymbol("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't setting a field name, it's writing a symbol value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

IonReaderBinarySpan pos = position;

if (pos == null)
if (position == null)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest leaving style fixes for an independent PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated

private final String ann = "ann";
private final String ben = "ben";
private static final String ANN = "ANN";
private static final String BEN = "BEN";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related; suggest separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated

int sid = value.symbolValue().getSid();

try {
value.setValue("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a positive test for this now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one

@Test
public void testSymbolWithEscapedNewline()
{
badValue("'\\\n'");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to fail because \\\n is an escaped newline, which expands to nothing within quoted text, leaving this as an empty symbol value. We should be testing that that case is now valid (and is treated as an empty symbol). This might actually be a good addition to ion-tests if it's not already there.

"'\\n'" is also an interesting test; it's just a different test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it by mistake, added it back again as a valid case. Will take a look if this is included in ion-tests and add it in a separate PR if necessary

@raganhan raganhan force-pushed the support-empty-symbol-42 branch from 0687f34 to e5fa879 Compare July 25, 2017 21:28
raganhan added 2 commits July 25, 2017 14:44
I was mistaken this is a unchecked exception so removal is fine.
Kept the class as @deprecated to avoid breaking clients
@raganhan
Copy link
Copy Markdown
Contributor Author

raganhan commented Jul 26, 2017 via email

@raganhan raganhan merged commit 3026661 into master Jul 26, 2017
@raganhan raganhan deleted the support-empty-symbol-42 branch July 26, 2017 17:39
tgregg pushed a commit that referenced this pull request Jun 21, 2018
Support for empty symbols, e.g. ''

Empty symbols are valid according to the spec so they need
to be allowed.
Removed usage of EmptySymbolException as it was only used in two cases:
* Empty symbols which are now supported
* Java null symbols which were converted to NPEs.

EmptySymbolException was kept as deprecated to avoid breaking any
client that depends on it

issue: #42
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

Successfully merging this pull request may close these issues.

3 participants