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 81206 - default_platform.xml can become corrupted
Summary: default_platform.xml can become corrupted
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Platform (show other bugs)
Version: 5.x
Hardware: All All
: P1 blocker (vote)
Assignee: Tomas Zezula
URL:
Keywords:
: 79650 83007 87041 89786 (view as bug list)
Depends on: 71828 72127 77665 79722 80367
Blocks:
  Show dependency tree
 
Reported: 2006-07-26 19:41 UTC by Jesse Glick
Modified: 2006-11-27 20:25 UTC (History)
1 user (show)

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 2006-07-26 19:41:03 UTC
I finally managed to reproduce the symptoms of issue #80367. All you need to do
is customize the default platform (e.g. add Javadoc); shut down; delete contents of

$userdir/config/Services/Platforms/org-netbeans-api-java-Platform/default_platform.xml

while leaving an empty file there; and restart.

I speculate that the root cause is some IOException (or RuntimeException) being
thrown from PlatformConvertor.W.write. If this happens, part of the file will be
written but will leave malformed XML behind. The exception should be printed,
but it would be in a previous IDE session and so we might not see it.

Anyway, it is clear that if write(...) does fail, we should not corrupt an
existing, valid platform definition! And even if a definition is corrupt, the
fix mentioned in issue #80367 is not adequate: while the NPE is no longer thrown
during startup, there is still no default platform (so most projects will be
unusable) and you cannot just create a platform named default_platform in the
new platform wizard as a workaround (since it says the file already exists).

So I think for this to be really fixed we also need to do these things:

1. PlatformConvertor should write to a buffer first, and only then write the
buffer to the file, to minimize the chance of producing a broken file due to a
halfway exception.

2. DefaultJavaPlatformProvider.getInstalledPlatforms should recover somehow from
files w/o InstanceCookie. Could just delete them but this is not helpful for the
default platform. Alternatively, J2SEPlatformModule.updateBuildProperties could
check for installedPlatforms.length == 0; in this case, copy
resources/templates/defaultPlatform.xml into
Services/Platforms/org-netbeans-api-java-Platform/default_platform.xml in order
to reset it to default. (In trunk you can instead use the API proposed in issue
#79722.)
Comment 1 Jesse Glick 2006-07-26 19:43:44 UTC
If it can be fixed, should probably be put in 5.5 too.
Comment 2 Jesse Glick 2006-07-27 07:42:16 UTC
*** Issue 79650 has been marked as a duplicate of this issue. ***
Comment 3 Jesse Glick 2006-07-27 08:01:58 UTC
So after some searching, found some more reported bugs. To the list of things
that should be fixed, I would now add

3. W.write should not print out lines of raw XML, as this is very dangerous.
(Will quietly write malformed XML if some metachars need to be escaped.) Should
create a DOM tree and use XMLUtil.write instead.

Given the number of duplicates of the dependent issues (and unreported
incidents, on feedback aliases, uninstall comments, ...) this group of bugs
seems to be a blocker for many people trying to use NB 5.0. IMHO it would
deserve a hotfix, although I suspect anyone encountering this bug would have
uninstalled NB already since it would be unusable.
Comment 4 Tomas Zezula 2006-07-31 15:33:35 UTC
The root case of the empty default_platform.xml is NPE from the
PlatformConvertor.shouldWriteSources() which is fixed in the dev and the NB 5.5
(http://www.netbeans.org/issues/show_bug.cgi?id=72127). Creating the document in
the buffer using DOM and storing it when it is created is a good idea, I will
change it in this way.
The work around for this issue is to delete the corrupted default_platform.xml
from the user dir.
Comment 5 Tomas Zezula 2006-08-01 14:36:19 UTC
Fixed in trunk.
PlatformConvertor uses DOM to store platform. The platform is firstly stored
into memory and after it the buffer is written onto the disk.
J2SEPlatformModule recovers broken default_platform.
I am going to integrate the PlatformConvertor changes also into the 5.5

Checking in src/org/netbeans/modules/java/j2seplatform/J2SEPlatformModule.java;
/cvs/java/j2seplatform/src/org/netbeans/modules/java/j2seplatform/J2SEPlatformModule.java,v
 <--  J2SEPlatformModule.java
new revision: 1.5; previous revision: 1.4
done
Checking in
src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java;
/cvs/java/j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java,v
 <--  PlatformConvertor.java
new revision: 1.18; previous revision: 1.17
done
Comment 6 Jesse Glick 2006-08-01 14:42:55 UTC
Note that the patch to J2SEPlatformModule.java will only work in trunk (after
issue #79722 is implemented), not in release55. So don't bother merging that part.

You may still need to check for non-XML-encodable property values in
writeProperties. (Really I've never understood why we write every Java system
property to these files to begin with, when we only ever read one or two, but
maybe you have some reason.)
Comment 7 Tomas Zezula 2006-08-01 15:01:15 UTC
I will add an XMLUtil.toAttributeValue() to check if the property name and value
is encodable.

There are several modules which need more properties (profiler uses
sun.arch.data.model). It is hard to say which properties to store.
Comment 8 Tomas Zezula 2006-08-01 16:20:25 UTC
Checking in
src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java;
/cvs/java/j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java,v
 <--  PlatformConvertor.java
new revision: 1.19; previous revision: 1.18
done
Comment 9 Tomas Zezula 2006-08-03 12:40:16 UTC
Integrated into 5.5
Checking in
src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java;
/cvs/java/j2seplatform/src/org/netbeans/modules/java/j2seplatform/platformdefinition/PlatformConvertor.java,v
 <--  PlatformConvertor.java
new revision: 1.13.22.1.2.3; previous revision: 1.13.22.1.2.2
done
Comment 10 Marian Mirilovic 2006-10-13 10:23:11 UTC
*** Issue 87041 has been marked as a duplicate of this issue. ***
Comment 11 Milan Kubec 2006-10-20 14:55:26 UTC
*** Issue 83007 has been marked as a duplicate of this issue. ***
Comment 12 Jesse Glick 2006-11-27 20:25:41 UTC
*** Issue 89786 has been marked as a duplicate of this issue. ***