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

IonStructLite bugfixes #155

Merged
merged 4 commits into from Sep 17, 2018
Merged

IonStructLite bugfixes #155

merged 4 commits into from Sep 17, 2018

Conversation

wesboyt
Copy link
Contributor

@wesboyt wesboyt commented Sep 13, 2018

Description of changes:
Updated ionstructlite so fieldmap will not always resolve as null on construction, added a boolean hasNullField to throw correctly when a fieldname does not resolve and correctness cannot be determined.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…onstruction, added a boolean hasNullField to throw correctly when a fieldname does not resolve and correctness cannot be determined.
@@ -402,9 +401,9 @@ public IonValue get(String fieldName)
IonValue field;

if (field_idx < 0) {
if(hasNullFieldName) throw new UnknownSymbolException("Because a field exists with an unknown name we cannot say for certain whether the requested field exists or not.");
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition needs a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the message is a bit wordy. The use of 'we', at least, feels too conversational for an exception message to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed ill add one.

@@ -738,6 +738,29 @@ public void testMakeNullRemovesChildsContainer()
val.getContainer());
}

@Test
public void testMapAfterClone()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this actually add coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really its more trying to check the cloning behavior between the container version and Hashmap version of IonStructLite.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't really have a way of differentiating between that internal behavior, though. If it's not adding anything, I'd vote to remove it, as there's already plenty of testing to verify that IonStructLite works correctly.


public UnknownSymbolException(int sid)
{
mySid = sid;
myText = null;
}
public UnknownSymbolException(String text)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change the parameter to 'message' and in getMessage just return it as-is. Because what's being passed in isn't actually symbol text. This constructor should be used when an unknown symbol causes a problem, but we don't know its symbol ID (as in the case of structs with unknown field names).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isnt it the symbol text?

Copy link
Contributor

Choose a reason for hiding this comment

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

What symbol would it be the text for? If you look at the only place you're actually using it, it's just a message.

@@ -450,11 +449,6 @@ public boolean add(IonValue child)
{
// TODO validate in struct.setFieldName
String text = child.getFieldNameSymbol().getText();
if (text != null)
{
validateFieldName(text);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this was silly.

@@ -483,6 +477,7 @@ protected void handle(IonValue newValue)
*/
private void _add(String fieldName, IonValueLite child)
{
if(!hasNullFieldName && fieldName == null) hasNullFieldName = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any benefit to checking !hasNullFieldName here? If it's already true, it's not harmful to set it to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will shortcircuit and prevent repeatedly setting hasNullFieldName

Copy link
Contributor

Choose a reason for hiding this comment

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

Who cares if you repeatedly set it though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

people paying for those clock cycles.

Copy link
Contributor

Choose a reason for hiding this comment

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

A branch operation is probably similar in cost to (or even more expensive than) writing to an in-memory primitive with a known address. Both, though, are pretty trivial.

If you're really concerned with clock cycles, you can replace the whole if statement with:

hasNullFieldName |= fieldName == null;

😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh nice

@@ -401,7 +401,7 @@ public IonValue get(String fieldName)
IonValue field;

if (field_idx < 0) {
if(hasNullFieldName) throw new UnknownSymbolException("Because a field exists with an unknown name we cannot say for certain whether the requested field exists or not.");
if(hasNullFieldName) throw new UnknownSymbolException("Unable to resolve fieldname due to null fields.");
Copy link
Contributor

Choose a reason for hiding this comment

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

'Null fields' is what's happening within the implementation, but from an Ion perspective isn't the issue. I don't know if this is any less wordy than the original, but here's my stab at it:

"Unable to determine whether the field exists because the struct contains field names with unknown text."

@wesboyt wesboyt merged commit 1a0af9e into master Sep 17, 2018
wesboyt added a commit that referenced this pull request Sep 17, 2018
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.

None yet

5 participants