Skip to content

Commit 892e14c

Browse files
committed
PersistenceManager deserialization logging improvement
Don't dump the serialized form on DataObjectNotFoundException when a TopComponent can't be deserialized. This is often harmless and happens for example when an opened project moved while NB was closed. A single warning line should be sufficient. Full exception is logged with FINE level.
1 parent b8eba3d commit 892e14c

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

platform/core.windows/src/org/netbeans/core/windows/persistence/PersistenceManager.java

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import java.beans.PropertyChangeEvent;
2323
import java.beans.PropertyChangeListener;
2424
import java.io.ByteArrayInputStream;
25-
import java.io.FileNotFoundException;
2625
import java.io.IOException;
2726
import java.io.InputStream;
28-
import java.io.InvalidObjectException;
2927
import java.io.NotSerializableException;
3028
import java.lang.ref.Reference;
3129
import java.lang.ref.WeakReference;
@@ -395,6 +393,7 @@ public FileObject getModesLocalFolder () throws IOException {
395393

396394
/** Listens to property changes in InstanceDataObject. Used to clean top component
397395
* cache when module owning given top component is disabled. */
396+
@Override
398397
public void propertyChange (PropertyChangeEvent evt) {
399398
if (DataObject.PROP_COOKIE.equals(evt.getPropertyName())) {
400399
Object obj = evt.getSource();
@@ -521,7 +520,6 @@ private TopComponent getTopComponentPersistentForID(String stringId, boolean des
521520
return null;
522521
}
523522
// search on disk
524-
IOException resultExc = null;
525523
try {
526524
DataObject dob = findTopComponentDataObject(getComponentsLocalFolder(), stringId);
527525
if (dob == null) {
@@ -574,7 +572,6 @@ private TopComponent getTopComponentPersistentForID(String stringId, boolean des
574572
// not found
575573
String excAnnotation = NbBundle.getMessage(PersistenceManager.class,
576574
"EXC_FailedLocateTC", stringId);
577-
resultExc = new FileNotFoundException(excAnnotation);
578575
LOG.log(warningLevelForDeserTC(stringId),
579576
"[PersistenceManager.getTopComponentForID]" // NOI18N
580577
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
@@ -584,48 +581,24 @@ private TopComponent getTopComponentPersistentForID(String stringId, boolean des
584581
// with new projects should not happen, since projects are not switched in winsys anymore.
585582
// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, resultExc);
586583
}
587-
} catch (NoClassDefFoundError ndfe) { // TEMP>>
584+
} catch (DataObjectNotFoundException ex) {
588585
LOG.log(warningLevelForDeserTC(stringId),
589586
"[PersistenceManager.getTopComponentForID]" // NOI18N
590587
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
591-
+ ndfe.getMessage(), ndfe);
592-
} catch (InvalidObjectException ioe) {
588+
+ ex.getMessage());
589+
LOG.log(Level.FINE, "", ex);
590+
} catch (NoClassDefFoundError | ClassNotFoundException | ClassCastException | IOException ex) {
593591
LOG.log(warningLevelForDeserTC(stringId),
594592
"[PersistenceManager.getTopComponentForID]" // NOI18N
595593
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
596-
+ ioe.getMessage(), ioe);
597-
} catch (DataObjectNotFoundException dnfe) {
598-
LOG.log(warningLevelForDeserTC(stringId),
599-
"[PersistenceManager.getTopComponentForID]" // NOI18N
600-
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
601-
+ " Object not found: " + dnfe.getMessage() // NOI18N
602-
+ ". It was probably deleted.", dnfe); // NOI18N
603-
} catch (ClassNotFoundException exc) {
604-
// ignore, will result in IOException fail below, annotate
605-
// and turn into IOExc
606-
LOG.log(warningLevelForDeserTC(stringId),
607-
"[PersistenceManager.getTopComponentForID]" // NOI18N
608-
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
609-
+ exc.getMessage(), exc);
610-
} catch (ClassCastException exc) {
611-
// instance is not top component (is broken), annotate and
612-
// turn into IOExc
613-
LOG.log(warningLevelForDeserTC(stringId),
614-
"[PersistenceManager.getTopComponentForID]" // NOI18N
615-
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
616-
+ exc.getMessage(), exc);
617-
} catch (IOException ioe) {
618-
LOG.log(warningLevelForDeserTC(stringId),
619-
"[PersistenceManager.getTopComponentForID]" // NOI18N
620-
+ " Problem when deserializing TopComponent for tcID:'" + stringId + "'. Reason: " // NOI18N
621-
+ ioe.getMessage(), ioe);
594+
+ ex.getMessage(), ex);
622595
}
623596
return null;
624597
}
625-
private final Set<String> warnedIDs = Collections.synchronizedSet(new HashSet<String>());
598+
private final Set<String> warnedIDs = Collections.synchronizedSet(new HashSet<>());
626599
/** Avoid printing dozens of warnings about the same ID in one IDE session. */
627600
private Level warningLevelForDeserTC(String id) {
628-
return warnedIDs.add(id) ? Level.INFO : Level.FINE;
601+
return warnedIDs.add(id) ? Level.WARNING : Level.FINE;
629602
}
630603

631604
/** @return Searches for TopComponent with given string id and returns
@@ -1039,6 +1012,7 @@ public XMLReader getXMLParser (DefaultHandler h) throws SAXException {
10391012
parser.setEntityResolver(new EntityResolver () {
10401013
/** Implementation of entity resolver. Points to the local DTD
10411014
* for our public ID */
1015+
@Override
10421016
public InputSource resolveEntity (String publicId, String systemId)
10431017
throws SAXException {
10441018
if (ModeParser.INSTANCE_DTD_ID_1_0.equals(publicId)
@@ -1389,6 +1363,7 @@ public TopComponentReference (TopComponent ref, String tcID) {
13891363
this.tcID = tcID;
13901364
}
13911365

1366+
@Override
13921367
public void run() {
13931368
removeGlobalTopComponentID(tcID);
13941369
}

0 commit comments

Comments
 (0)