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 120848 - Incorrect implementation of FreeformFileEncodingQueryImpl
Summary: Incorrect implementation of FreeformFileEncodingQueryImpl
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Ant Freeform (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Milan Kubec
URL:
Keywords:
Depends on:
Blocks: 120508
  Show dependency tree
 
Reported: 2007-11-01 17:02 UTC by Jesse Glick
Modified: 2007-11-02 18:57 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2007-11-01 17:02:19 UTC
There are several problems I can see with this class today.

1. The distinction between typed and untyped source roots is unnecessary and wrong. The correct behavior is to apply the
most specific <source-folder>, i.e. that folder which is the nearest ancestor of the file.

2. Use of FileUtil.isParentOf ignores the fact that this method returns false in case the folder itself is passed as the
second argument, which is in fact done by java/source.

3. Charset.forName should be called during computeEncodingsCache, and IllegalCharsetNameException should be reported.

4. There is no unit test, which is inexcusable for a query impl.

5. The file currently shows unchecked compiler warnings - please fix these.

6. Most significantly, the impl is completely broken for projects which use property substitutions in <location>. For
example, try making the Freeform Anagram sample (Freeform Project Extras module). The query will not work because
<location>${src.dir}</location> is not correctly interpreted. You need to use PropertyEvaluator.evaluate (and beware of
a null return value). This also implies that you need to attach a listener to the PropertyEvaluator
(AntProjectListener.propertiesChanged does _not_ suffice) and clear the cache in case you receive a prop change event,
as it might have affected source folder locations.

7. Special-case code for location.equals(".") is unnecessary; just use helper.resolveFileObject and it will handle such
paths. In fact the current code will not work at all for <location>../src</location>, for example.
Comment 1 Jesse Glick 2007-11-01 17:03:27 UTC
By the way, I added logging to both FileEncodingQuery and ProjectFileEncodingQueryImplementation, which may prove useful
in getting diagnostics from users.
Comment 2 Milan Kubec 2007-11-02 11:19:27 UTC
I'm already working on this issue, I just forgot to set TM.
Comment 3 Milan Kubec 2007-11-02 18:57:46 UTC
Better impl. of FreeformFileEncodingQueryImpl.

Checking in ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformFileEncodingQueryImpl.java;
/cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformFileEncodingQueryImpl.java,v  <-- 
FreeformFileEncodingQueryImpl.java
new revision: 1.5; previous revision: 1.4
done
Checking in ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java;
/cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java,v  <--  FreeformProject.java
new revision: 1.53; previous revision: 1.52
done
Checking in java/freeform/test/unit/src/org/netbeans/modules/java/freeform/FileEncodingQueryTest.java;
/cvs/java/freeform/test/unit/src/org/netbeans/modules/java/freeform/FileEncodingQueryTest.java,v  <-- 
FileEncodingQueryTest.java
new revision: 1.4; previous revision: 1.3
done
Checking in java/freeform/src/org/netbeans/modules/java/freeform/ui/ProjectModel.java;
/cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ProjectModel.java,v  <--  ProjectModel.java
new revision: 1.18; previous revision: 1.17
done

ad 4) There was a test but under java/freeform/test, I've updated that test.