Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 332431 - org.eclipse.equinox.internal.security.storage.StorageUtils.getOutputStream(URL url) can't handle Whitespaces
Summary: org.eclipse.equinox.internal.security.storage.StorageUtils.getOutputStream(UR...
Status: CLOSED WONTFIX
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Security (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Security Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-13 07:31 EST by Jan Kresser CLA
Modified: 2021-04-15 07:42 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kresser CLA 2010-12-13 07:31:20 EST
Build Identifier: 20100917-0705

When using the SecurePreferencesFactory on a custom location containing a whitespace in the path, changing them and calling "flush()" to persist them in the filesystem causes the changed preferences to be written to another directory/file than the one they were originally read from.
SecurePreferencesFactory.open(location, options) only accepts an URL for a location. The ISecurePreferences which are returned can be changed and "flush()" should write the changes back to the filesystem. 
When initializing the object (reading from the filesystem), the method org.eclipse.equinox.internal.security.storage.StorageUtils.getInputStream(URL url) is used to retrieve the input stream, which works fine because it makes use of java.net.URL.openStream(), which doesn't have problems with whitespaces. org.eclipse.equinox.security.storage.ISecurePreferences.flush() on the other hand uses org.eclipse.equinox.internal.security.storage.StorageUtils.getOutputStream(URL) to retrieve the output stream to write the changed file to. This method retrieves the local file to write to as follows: 
File file = new File(url.getPath()); 
java.net.URL.getPath() returns (according to the Java Doc) "the path part of this URL, or an empty string if one does not exist" , with spaces escaped to "%20". A new File/Folder will be created with this name and the preferences will be flushed there. 
Local checks show that the following code doesn't have problems with whitespaces (or other characters which might be escaped by the URL Object):
File file = new File(url.toURI()); 
Anyway, I don't know which drawbacks this method has.
Another possibility to fix the problem might be to "manually" un-escape masked characters which are returned by url.getPath().

Reproducible: Always

Steps to Reproduce:
Write the following code which uses org.eclipse.equinox.security.*
1. call org.eclipse.equinox.security.storage.SecurePreferencesFactory.open(URL, Map) with an URL pointing to a local file which has a space in it's path, e.g. "C:\tmp\folder with space\preferences.prf" :
ISecurePreferences preferences = SecurePreferencesFactory.open(new File("C:\\tmp\\folder with space\\preferences.prf").toURI().toURL(), new HashMap<String, String>());
2. On the returned ISecurePreferences object, add a new Node:
ISecurePreferences node = preferences.node("node");
node.put("key", "value", true); 
3. Persist the changed Preferences:
preferences.flush();
4. Check in the Filesystem: 
The wrong file "C:\tmp\folder%20with%20space\preferences.prf" does exist, but the (intended) file "C:\tmp\folder with space\preferences.prf" doesn't
Comment 1 Eclipse Genie CLA 2019-06-17 12:22:34 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Dmitry Zagrebaev CLA 2021-04-15 07:42:06 EDT
The error is reproduced. Please reopen.