Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Validate that paths are not a subpath of another (bean) property #24

Closed
ljacqu opened this issue Oct 22, 2016 · 2 comments
Closed

Validate that paths are not a subpath of another (bean) property #24

ljacqu opened this issue Oct 22, 2016 · 2 comments

Comments

@ljacqu
Copy link
Member

ljacqu commented Oct 22, 2016

Right now, it's possible to do this:

class Bean {
   String name;
   int length;
}

class Properties implements SettingsHolder {
  public static final Property<Bean> BEAN = new BeanProperty("bean", new Bean());
  // subpath of bean above!
  public static final Property<Integer> LENGTH = new IntegerProperty("bean.length", 5);
}

class Main {
  public void main(String... args) {
    SettingsManager manager = new SettingsManager(resource, null, Properties.class);
    Bean bean = manager.getProperty(Properties.BEAN); // e.g. Bean(name="hi", length=5)
    int length = manager.getProperty(Properties.LENGTH); // 5

    // but now:
    manager.setProperty(Properties.BEAN, new Bean("hello", -1));
    manager.setProperty(Properties.LENGTH, 20);

    // results in inconsistent state (which cannot be exported in a sensible manner):
    manager.getProperty(Properties.BEAN); // returns Bean(name="hello", length=-1)
    manager.getProperty(Properties.LENGTH); // returns 20
  }
}

This can be handled in a few ways:

  • somehow keep track of "bean paths" and throw if there is a property like LENGTH which is in a "bean path." Need to keep all paths as we may encounter LENGTH before BEAN. This could be done in ConfigurationDataBuilder, which would work out quite well.
  • provide a validation tool that handles this and more. Relies on the user knowing about it and running it to validate his config...
  • do nothing concerning this; if such a case happens we just don't guarantee that it works

I like the first point because we could validate in general that there are no path conflicts (for any types, property at path path and a property at path path.subpath are a conflict).

@ljacqu
Copy link
Member Author

ljacqu commented Feb 12, 2017

Relates to #5

@ljacqu
Copy link
Member Author

ljacqu commented Apr 13, 2020

Closing as duplicate as by default it cannot happen anymore: PropertyListBuilder checks for overlapping paths

@ljacqu ljacqu closed this as completed Apr 13, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

1 participant