This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 217377 - add NbPreferences.forModule(Preferences, Class) to apis
Summary: add NbPreferences.forModule(Preferences, Class) to apis
Status: RESOLVED WONTFIX
Alias: None
Product: platform
Classification: Unclassified
Component: Options&Settings (show other bugs)
Version: 7.3
Hardware: PC Mac OS X
: P3 normal (vote)
Assignee: apireviews
URL:
Keywords: API_REVIEW, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2012-08-24 14:46 UTC by Milos Kleint
Modified: 2012-09-04 07:01 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
proposed api change along with impl (8.46 KB, patch)
2012-08-24 20:21 UTC, Milos Kleint
Details | Diff
change in projectui forPackage -> forModule (4.29 KB, patch)
2012-08-24 20:23 UTC, Milos Kleint
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Milos Kleint 2012-08-24 14:46:27 UTC
when working on issue 91031, I've encountered a usecase when I would like to use forModule(Class) on a non-root Preferences node, typically the node representing the project group. That way both the group and not group preferences tree structures are the same.
Comment 1 Milos Kleint 2012-08-24 20:21:07 UTC
Created attachment 123559 [details]
proposed api change along with impl
Comment 2 Milos Kleint 2012-08-24 20:23:24 UTC
Created attachment 123560 [details]
change in projectui forPackage -> forModule
Comment 3 Milos Kleint 2012-08-24 20:24:27 UTC
please review this small api change to NbPreferences
Comment 4 Jaroslav Tulach 2012-08-28 09:15:12 UTC
Y01 Summary is unlikely correct: <summary>UNC-safe File / URI interconversion</summary>

Y02 Adding new method into NbPreferences.Provider interface is likely not backward compatible and will fail the build. Try "ant check-sigtest" to verify. Do you need this method at all? I thought the logic of the preferencesForModule(root, clazz) is hardcoded in the API and does not need anything from the SPI...
Comment 5 Milos Kleint 2012-08-28 09:23:53 UTC
(In reply to comment #4)
> Y01 Summary is unlikely correct: <summary>UNC-safe File / URI
> interconversion</summary>

sure, thanks. copy and paste error.

> 
> Y02 Adding new method into NbPreferences.Provider interface is likely not
> backward compatible and will fail the build. Try "ant check-sigtest" to verify.
> Do you need this method at all? I thought the logic of the
> preferencesForModule(root, clazz) is hardcoded in the API and does not need
> anything from the SPI...

not really, the logic itself if done inside the Provider. It's indeed not backward compatible, but unlikely to affect anyone. Unless someone uses a different storage backend?

There is no backward compatible solution really. If the Provider doesn't implement the new method, there's no way to return a correct value in NBPreferences. Eg. if we extend Provider with Provider2 and add the new method there, what will the behaviour be if the implementation only fullfils the Provider contract?
Comment 6 Jaroslav Tulach 2012-08-30 10:38:22 UTC
(In reply to comment #5)
> There is no backward compatible solution really. If the Provider doesn't
> implement the new method, there's no way to return a correct value in
> NBPreferences. Eg. if we extend Provider with Provider2 and add the new method
> there, what will the behaviour be if the implementation only fullfils the
> Provider contract?

I guess we could achieve the same without introducing Provider2 (and without changing Provider incompatibly). Here is my attempt:

    public static Preferences forModule(Preferences from, Class cls) {
        Preferences tmp = forModule(cls);
        StringBuilder path = new StringBuilder();
        while (tmp != root()) {
            path.insert(0, '/');
            path.insert(0, tmp.name());
            tmp = tmp.parent();
        }
        return from.node(path.toString());
    }

The Javadoc of the node(String) method says that the nodes are not guaranteed to be permanent until flush() is called on them. That is why we only need to make sure the "tmp" node is not going to be written the disk at all, if it was created and remained empty. That requires a test. If the test passes, then we may need no API at all, as the above forModule(from, cls) method is trivial and it has only one known use so far...
Comment 7 Milos Kleint 2012-08-30 10:57:47 UTC
(In reply to comment #6)
> The Javadoc of the node(String) method says that the nodes are not guaranteed
> to be permanent until flush() is called on them. That is why we only need to
> make sure the "tmp" node is not going to be written the disk at all, if it was
> created and remained empty. That requires a test. If the test passes, then we
> may need no API at all, as the above forModule(from, cls) method is trivial and
> it has only one known use so far...

That's a rather shaky solution, just for sake of backward compatibility, let's just forget about then.
Comment 8 Milos Kleint 2012-09-04 07:01:51 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > The Javadoc of the node(String) method says that the nodes are not guaranteed
> > to be permanent until flush() is called on them. That is why we only need to
> > make sure the "tmp" node is not going to be written the disk at all, if it was
> > created and remained empty. That requires a test. If the test passes, then we
> > may need no API at all, as the above forModule(from, cls) method is trivial and
> > it has only one known use so far...
> 
> That's a rather shaky solution, just for sake of backward compatibility, let's
> just forget about then.

let me describe in more detail why I think it's unstable solution.

What are the alternatives
1. use the above mentioned workaround in project only without any additional API. Affects only IDE users (as only a minority of platform users uses projects) and we can count on the IDE's own implementation of Provider

2. change the Provider API in non backward compatible way (suggested by this report). Affects only a small minority of platform users (in the IDE, we would scream out loud of some module implemented it) and gives them a clear, simple way to upgrade.

ON the contrary, your proposal is nominally backward compatible but communicates the change in a very bad way. The minority of platforms users affected might get spurious, subtle problems undiscoverable without reading the platform's codebase.