diff --git a/openide.util/src/org/openide/util/Utilities.java b/openide.util/src/org/openide/util/Utilities.java
--- a/openide.util/src/org/openide/util/Utilities.java
+++ b/openide.util/src/org/openide/util/Utilities.java
@@ -2378,6 +2378,9 @@
* # rename of whole package
* org.someoldpackage=org.my.new.package.structure
*
+ * # class was removed without replacement
+ * org.mypackage.OldClass=
+ *
*
* Btw. one can use spaces instead of =
sign.
* For a real world example
diff --git a/settings/apichanges.xml b/settings/apichanges.xml
--- a/settings/apichanges.xml
+++ b/settings/apichanges.xml
@@ -105,6 +105,23 @@
+
+
+ Ignore settings for intentionally removed classes.
+
+
+
+
+
+ To prevent ClassNotFoundException while loading *.settings where
+ intentionally removed class is either in <instance class="..."/>
+ or <serialdata class="..."> it is possible to declare such
+ class in META-INF/netbeans/translate.names
. If class name
+ maps to empty string, it is ignored. E.g.:
+ org.mypackage.OldClass=
+
+
+
Provides support for Lookups.forPath
diff --git a/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java b/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java
--- a/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java
+++ b/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java
@@ -114,8 +114,11 @@
SerialDataConvertor.SettingsInstance si = createInstance(null);
if (isModuleEnabled(si)) {
- instance = si;
- lkpContent.add(instance);
+ // 137240 - if instanceName is empty string, it doesn't provide instance
+ if (si.instanceName().length() > 0) {
+ instance = si;
+ lkpContent.add(instance);
+ }
}
lkpContent.add(this);
node = new SerialDataConvertor.NodeConvertor();
@@ -212,14 +215,14 @@
}
}
if (XMLSettingsSupport.err.isLoggable(Level.FINE)) XMLSettingsSupport.err.fine("need recreate: " + recreate + " for " + this.dobj); // NOI18N
- if (isModuleEnabled(si)) {
+ if (isModuleEnabled(si) && si.instanceName().length() > 0) { // 137240 - if instanceName is empty string, it doesn't provide instance
instance = si;
lkpContent.set(Arrays.asList(new Object [] { this, si }), null);
if (XMLSettingsSupport.err.isLoggable(Level.FINE)) XMLSettingsSupport.err.fine("module enabled: " + this.dobj); // NOI18N
} else {
lkpContent.set(Collections.singleton(this), null);
instance = null;
- if (XMLSettingsSupport.err.isLoggable(Level.FINE)) XMLSettingsSupport.err.fine("module disabled: " + this.dobj); // NOI18N
+ if (XMLSettingsSupport.err.isLoggable(Level.FINE)) XMLSettingsSupport.err.fine("module disabled: " + this.dobj + " or instanceName is empty: " + si.instanceName()); // NOI18N
}
lkpContent.add(this, node);
@@ -229,7 +232,9 @@
if (isModuleEnabled(si) && recreate) {
if (XMLSettingsSupport.err.isLoggable(Level.FINE)) XMLSettingsSupport.err.fine("recreating: " + this.dobj); // NOI18N
try {
- instance.instanceCreate();
+ if(instance != null) {
+ instance.instanceCreate();
+ }
} catch (Exception ex) {
XMLSettingsSupport.err.log(Level.WARNING, null, ex);
}
diff --git a/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java b/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java
--- a/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java
+++ b/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java
@@ -464,8 +464,10 @@
throw new SAXException(nfe);
}
} else if (ELM_INSTANCEOF.equals(qName)) {
- instanceOf.add(org.openide.util.Utilities.translate(
- attribs.getValue(ATR_INSTANCEOF_CLASS)));
+ String instanceOfName = org.openide.util.Utilities.translate(attribs.getValue(ATR_INSTANCEOF_CLASS));
+ if (instanceOfName.length() > 0) {
+ instanceOf.add(instanceOfName);
+ }
} else if (ELM_INSTANCE.equals(qName)) {
instanceClass = attribs.getValue(ATR_INSTANCE_CLASS);
if (instanceClass == null) {
diff --git a/settings/test/unit/src/META-INF/netbeans/translate.names b/settings/test/unit/src/META-INF/netbeans/translate.names
--- a/settings/test/unit/src/META-INF/netbeans/translate.names
+++ b/settings/test/unit/src/META-INF/netbeans/translate.names
@@ -40,3 +40,4 @@
# Old repackaging.
org.UnknownClass=org.netbeans.modules.settings.convertors.FooSetting
org.netbeans.modules.settings.convertors.ObsoleteClass=org.netbeans.modules.settings.convertors.FooSetting
+org.netbeans.modules.settings.convertors.RemovedClass=
diff --git a/settings/test/unit/src/org/netbeans/modules/settings/convertors/RemovedClass.java b/settings/test/unit/src/org/netbeans/modules/settings/convertors/RemovedClass.java
new file mode 100644
--- /dev/null
+++ b/settings/test/unit/src/org/netbeans/modules/settings/convertors/RemovedClass.java
@@ -0,0 +1,47 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.settings.convertors;
+
+/**
+ * Used in SerialDataConvertorTest.
+ */
+public class RemovedClass {
+
+}
diff --git a/settings/test/unit/src/org/netbeans/modules/settings/convertors/SerialDataConvertorTest.java b/settings/test/unit/src/org/netbeans/modules/settings/convertors/SerialDataConvertorTest.java
--- a/settings/test/unit/src/org/netbeans/modules/settings/convertors/SerialDataConvertorTest.java
+++ b/settings/test/unit/src/org/netbeans/modules/settings/convertors/SerialDataConvertorTest.java
@@ -581,6 +581,26 @@
assertNull("There shouldn't be provided InstanceCookie for disabled module", ic);
}
+ /** If class name is mapped to an empty string in META-INF.netbeans/translate.names,
+ * InstanceCookie should not be created and instanceOf should return false. */
+ public void testRemovedClass137240() throws DataObjectNotFoundException {
+ FileObject RemovedClassFO = lfs.findResource("/Settings/org-netbeans-modules-settings-convertors-FooSettingRemovedClass.settings");
+ assertNotNull(RemovedClassFO);
+ DataObject ido = DataObject.find(RemovedClassFO);
+ InstanceCookie ic = ido.getCookie(InstanceCookie.class);
+ assertNull("InstanceCookie issued for removed class.", ic);
+ FileObject unknownSerialFO = lfs.findResource("/Settings/org-netbeans-modules-settings-convertors-FooSettingRemovedClassSerial.settings");
+ assertNotNull(unknownSerialFO);
+ ido = DataObject.find(unknownSerialFO);
+ InstanceCookie icSerial = ido.getCookie(InstanceCookie.class);
+ assertNull("InstanceCookie issued for removed class.", icSerial);
+ FileObject unknownInstanceOfFO = lfs.findResource("/Settings/org-netbeans-modules-settings-convertors-FooSettingRemovedClassInstanceOf.settings");
+ assertNotNull(unknownInstanceOfFO);
+ ido = DataObject.find(unknownInstanceOfFO);
+ InstanceCookie.Of icOf = ido.getCookie(InstanceCookie.Of.class);
+ assertFalse("instanceOf should not return true for removed class.", icOf.instanceOf(RemovedClass.class));
+ }
+
public void testDeleteOfUnrecognizedSettingsFile () throws Exception {
final FileObject corrupted = lfs.findResource("/Settings/org-netbeans-modules-settings-convertors-FooSettingUnrecognizedSettingsFile.settings");
assertNotNull(corrupted);
diff --git a/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml b/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml
--- a/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml
+++ b/settings/test/unit/src/org/netbeans/modules/settings/convertors/data/mf-layer.xml
@@ -90,6 +90,36 @@
]]>
+
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+
+
+]]>
+
+
+
+
+
+
+
+ ACED00057372
+
+]]>
+