Skip to content

Fix error cases with Component::findStateVariable(). #2083

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

Merged
merged 4 commits into from
Feb 22, 2018

Conversation

chrisdembia
Copy link
Member

Fixes #2082

Brief summary of changes

Testing I've completed

  • Added a test case that failed without this PR. With the bug fix, the tests now pass.

Looking for feedback on...

  • Is the use of ComponentPath okay?

CHANGELOG.md (choose one)

  • no need to update because...this bug was introduced after 3.3.

Copy link
Member

@tkuchida tkuchida left a comment

Choose a reason for hiding this comment

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

One suggestion; otherwise, LGTM 👍

SimTK_TEST(b->getStateVariableValue(s, "../subState") == 20);
SimTK_TEST(b->getStateVariableValue(s, "../../internalSub/subState") == 10);

top.getStateVariableValue(s, "a/b/subState");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think L1079 is necessary (see L1072).

@chrisdembia
Copy link
Member Author

Thanks @tkuchida

Copy link
Member

@aseth1 aseth1 left a comment

Choose a reason for hiding this comment

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

I like that the method now traverses directly to the Component (made possible by your changes to include the path in updateFromXMLNode in #1751).

Now, I think we should rename findStateVariable( name ) to traverseToStateVariable( pathName ) since there is no more "finding" that occurs.

@chrisdembia
Copy link
Member Author

@aseth1 thanks for your review. I renamed the function.

(made possible by your changes to include the path in updateFromXMLNode in #1751).

I'm not sure this is true. findStateVariable() could only be used after finalizeFromProperties(), during which I think all the socket paths are corrected (even without #1751), because of the logic here:

catch (const ComponentNotFoundOnSpecifiedPath& ex) {
if (Object::getDebugLevel() > 0) {
// TODO once we fix how connections are established when building
// models programmatically, we should show this warning even for
// debug level 0.
std::cout << ex.getMessage() << std::endl;
}
comp = root.template findComponent<C>(path.toString());

Ready for review again.

Copy link
Member

@aseth1 aseth1 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

* branch of the Component tree (in such a case, the specified path might
* begin with "../").
* This returns nullptr if a StateVariable does not exist at the specified
* path or if the path is invalid.
Copy link
Member

Choose a reason for hiding this comment

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

👍

@aseth1
Copy link
Member

aseth1 commented Feb 13, 2018

@chrisdembia the travis push build failure looks like a legit test failure.

@chrisdembia
Copy link
Member Author

Ready for review again.

@chrisdembia
Copy link
Member Author

This PR has 2 reviews and passes CI. Would either reviewer (@tkuchida or @aseth1) be interested in merging this?

@tkuchida
Copy link
Member

Re-reviewed and looks 👍; merging.

@tkuchida tkuchida merged commit 69c25d0 into master Feb 22, 2018
@tkuchida tkuchida deleted the setStateVariableValue_invalidpath branch February 22, 2018 21:09
@chrisdembia
Copy link
Member Author

Thanks @tkuchida

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.

Component::getStateVariableValue() silently accepts incorrect paths
3 participants