Bläddra i källkod

FS: Fix lazy initialization of non-volatile static field

The 'factory' field is lazy initialized in the detect() method.

According to FindBugs:

   Because the compiler or processor may reorder instructions, threads
   are not guaranteed to see a completely initialized object, if the
   method can be called by multiple threads.

Fix this by declaring the member as 'volatile'.

Change-Id: Ib32663bb28c9564584256e01f625b4e7875e6223
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v4.6.0.201612231935-r
David Pursehouse 7 år sedan
förälder
incheckning
bdf3e43d76
1 ändrade filer med 1 tillägg och 1 borttagningar
  1. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java Visa fil

@@ -164,7 +164,7 @@ public abstract class FS {
/** The auto-detected implementation selected for this operating system and JRE. */
public static final FS DETECTED = detect();

private static FSFactory factory;
private volatile static FSFactory factory;

/**
* Auto-detect the appropriate file system abstraction.

Laddar…
Avbryt
Spara