mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-11 11:06:25 +00:00
[JENKINS-45892] Enhanced diagnostics (#2997)
* [JENKINS-45892] Enhanced diagnostics. * Refined fix which should avoid a needless warning when called from MultiBranchProject.onLoad.
This commit is contained in:
1 parent
4d60ca6de6
commit
a032c59e06
2 files changed
+14
-3
No files matched your search
@@ -120,6 +120,7 @@ public final class XmlFile {
|
||||
private final XStream xs;
|
||||
private final File file;
|
||||
private static final Map<Object, Void> beingWritten = Collections.synchronizedMap(new IdentityHashMap<>());
|
||||
private static final ThreadLocal<File> writing = new ThreadLocal<>();
|
||||
|
||||
public XmlFile(File file) {
|
||||
this(DEFAULT_XSTREAM,file);
|
||||
@@ -175,10 +176,12 @@ public final class XmlFile {
|
||||
try {
|
||||
w.write("<?xml version='1.0' encoding='UTF-8'?>\n");
|
||||
beingWritten.put(o, null);
|
||||
writing.set(file);
|
||||
try {
|
||||
xs.toXML(o, w);
|
||||
} finally {
|
||||
beingWritten.remove(o);
|
||||
writing.set(null);
|
||||
}
|
||||
w.commit();
|
||||
} catch(StreamException e) {
|
||||
@@ -200,11 +203,11 @@ public final class XmlFile {
|
||||
* @since 2.74
|
||||
*/
|
||||
public static Object replaceIfNotAtTopLevel(Object o, Supplier<Object> replacement) {
|
||||
if (beingWritten.containsKey(o)) {
|
||||
File currentlyWriting = writing.get();
|
||||
if (beingWritten.containsKey(o) || currentlyWriting == null) {
|
||||
return o;
|
||||
} else {
|
||||
// Unfortunately we cannot easily tell which XML file is actually being saved here, at least without implementing a custom Converter.
|
||||
LOGGER.log(Level.WARNING, "JENKINS-45892: reference to {0} being saved but not at top level", o);
|
||||
LOGGER.log(Level.WARNING, "JENKINS-45892: reference to " + o + " being saved from unexpected " + currentlyWriting, new IllegalStateException());
|
||||
return replacement.get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user