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 208779 - DataShadows should translate the original URL for b/w compatibility
Summary: DataShadows should translate the original URL for b/w compatibility
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Data Systems (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks: 208058
  Show dependency tree
 
Reported: 2012-02-23 09:39 UTC by Svata Dedic
Modified: 2012-03-25 09:45 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proposed changes (3.76 KB, patch)
2012-02-23 09:42 UTC, Svata Dedic
Details | Diff
Patch addressing JG01-JG05 (15.83 KB, patch)
2012-02-27 14:18 UTC, Svata Dedic
Details | Diff
Disallowed special chars in translated filenames (13.79 KB, patch)
2012-03-15 13:17 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Svata Dedic 2012-02-23 09:39:40 UTC
Discovered while working on defect # : keymaps store the shortcuts as DataShadows pointing to actions triggered by the keystroke. However if the action .instance file moves/renames (e.g. WhereUsed during 7.1 release), the shortcuts become broken.

Specifically broken DataShadows that point on SFS (layer) is a more general case than just shortcuts, so I think some translation mechanism could be used to translate moved paths.

Current Utilities.translate() is capable of such function, except its Javadoc claims it can be only used to translate classnames. 

Attaching a patch to DataShadow + javadoc clarification in Utilities for review.
Comment 1 Svata Dedic 2012-02-23 09:42:11 UTC
Created attachment 116046 [details]
Proposed changes
Comment 2 Jesse Glick 2012-02-23 14:42:54 UTC
(In reply to comment #0)
> Discovered while working on defect # :

What issue? Should it not be dependent on this?


[JG01] Javadoc omits ".instance" suffix in value side; accident?

Actions/Refactoring/RefactoringWhereUsed.instance=Actions/Refactoring/org-netbeans-modules-refactoring-api-ui-WhereUsedAction


[JG02] urlText.substring(prefix.length()) and new URI(prefix + translated) are not in general correct ways to interconvert between URI fragments and FileObject paths; try it with "Actions/Some Category/My Action #1.instance" and you will see why.

URI.relativize is not appropriate either, since the return value is still an encoded URI, and similarly for URI.resolve.

In general you need to use the URI.path field to properly escape and unescape path components. (Note that for FOs on the SFS, URI.path != FO.path, since there is normally a "nbhost/" prefix, so you still need to compare to SFS root.)


[JG03] translated != cfgPart assumes that that U.t returns the identical String object if not translated. Safer to use !equals.


[JG04] Your code does not seem to handle the second branch of the if-clause, where path is not a URI but an actual FileObject path (meaning JG02 does not apply here).


[JG05] No unit test, especially for JG02 and JG04.
Comment 3 Svata Dedic 2012-02-27 14:18:27 UTC
Created attachment 116136 [details]
Patch addressing JG01-JG05

[JG01] corrected.

[JG03] Utilities.translate is documented  to return the exactly same reference if no translation is defined. But changing to be more robust.

[JG02] Correct, thanks. I still think, that comparing encoded URIs for substring to find whether URI belongs to SFS is valid - both should be translated the same way. The composition was NOT correct, as you demonstrated - so I changed that part

[JG04] Case added

[JG05] Testcases added
Comment 4 Jesse Glick 2012-02-27 20:35:57 UTC
[JG06] Use toString, not toASCIIString. You do not want non-ASCII chars translated to some weird escapes here - just leave them alone.


[JG07] cfgRootURI.resolve(translated) is probably wrong as I said in JG02 - this will throw IAE if translated contains spaces or the like.

Remember that translate.names keys and values are file paths, not URI fragments, contrary to what your unit test seems to be expecting. (Why Utilities does not just use java.util.Properties, I am not sure, but anyway it reads the file in UTF-8 and splits on the first '=' or ' '.)
Comment 5 Svata Dedic 2012-02-27 21:14:43 UTC
re.: contents of translate.names: actually the format depends on definition being put in javadoc. 

The syntax of the file is currently defined so that lines are cut after first '#' (comments). So at least # should be somehow escaped. Instead of inventing yet another escaping scheme, I would prefer to use standard URL encoding instead. 

re.: excessive escaping (toASCIIString) - will try to change to less obtrusive form; translate.names is read as UTF-8 after all.

re.: resolve(translated) throwing exception - will not throw, if contents of translate.names is according to rules (e.g. all spaces must be %-encoded). Sadly the URL encoding is already consumed for # escaping, so either we need to accept URL fragments as key/value pairs, or invent special encoding for #.
Comment 6 Jesse Glick 2012-02-27 22:22:49 UTC
(In reply to comment #5)
> actually the format depends on definition being put in javadoc.

If you are adding the ability to translate paths then I suppose you can invent a new format and document it.

> the URL encoding is already consumed for # escaping

Do not understand what this sentence means but perhaps it does not matter.
Comment 7 Svata Dedic 2012-02-28 11:25:41 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > actually the format depends on definition being put in javadoc.
> 
> If you are adding the ability to translate paths then I suppose you can invent
> a new format and document it.

OK, so I can as well change the javadoc to specify that the filenames should be written as URI paths with the appropriate encoding. For completness, we also may need to escape '=' as well (another char illegal for class names, but permited for filenames).

All is about the decision what rules are easier to follow and code complexity

1/ filenames, but encode # and = using some (RFC 2396?) encoding. In this case, we must change handling of ' ' in code, but most of filenames will be written in a natural way.

2/ specify filenames as URI paths PLUS encode '=' using RFC 2396, if part of filename. This scheme matches what FileObject.toURI() produces for a FileObject, except '='.

3/ other encoding system, which translates # and = to other characters


What do you suggest, from the developer's perspective ?
Comment 8 Jesse Glick 2012-02-28 17:05:48 UTC
Or

4. Document that '=' and any characters (including ' ') which would need URI escaping may not be used in either the key or value in translate.names, unless and until someone needs such a feature.

Normally layer files are given fairly conservative filenames - ^[/a-zA-Z0-9$_.+-]+$ - with only a few exceptions:

Actions/Build/Set Request Parameters.instance, Actions/Help/Show BluePrints.instance, Actions/Help/Show Welcome.instance - bad practice
J2EE/DeploymentPlugins/APPSERVERSJS/DeploymentFileNames/CAR/META-INF\sun-application-client.xml and similar - ????
Keymaps/Emacs/C-X 1.shadow and similar - OK, required by multikey syntax
Templates/Project/Web/Html Project - bad practice
Toolbars/Jemmy Support/ - bad practice

so it is unlikely you would need to translate them, I think.
Comment 9 Svata Dedic 2012-02-28 19:55:37 UTC
OK, given you're the original author of the counter-example (with chars like '#', ' '), I would gladly agree with (4), as the simplest, yet solving the most common cases. Filenames on sysfs (cfg) could be 'sane', if we want to write them on FAT32 fs ...

if you agree, I'll simplify the patch back to non-URI and change the javadoc appropriately.
Comment 10 Jesse Glick 2012-02-28 20:25:53 UTC
The motivation for JG02 was that your code was pretending to work with all filenames but really would not. If it is easier to just explicitly reject certain pathological cases then do so and document it.
Comment 11 Svata Dedic 2012-03-15 13:17:13 UTC
Created attachment 116763 [details]
Disallowed special chars in translated filenames

[JG02] Addressed by documentation for Utilities.translate

[JG04], [JG05] addressed by previous patch; removed unnecessary testcases.

[JG06], [JG07] become IMHO obsolete because of constraints on allowed filenames.
Comment 12 Jesse Glick 2012-03-20 03:07:08 UTC
OK from me.
Comment 13 Svata Dedic 2012-03-23 12:00:37 UTC
Changed in jet-main #4c80493a0c8c
Comment 14 Quality Engineering 2012-03-24 11:00:48 UTC
Integrated into 'main-golden', will be available in build *201203240400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/4c80493a0c8c
User: Svata Dedic <sdedic@netbeans.org>
Log: #208779: DataShadows use translate.names if the original file could not be found - bw compatibility
Comment 15 Quality Engineering 2012-03-25 09:45:29 UTC
Integrated into 'main-golden', will be available in build *201203250401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/4c80493a0c8c
User: Svata Dedic <sdedic@netbeans.org>
Log: #208779: DataShadows use translate.names if the original file could not be found - bw compatibility