diff --git a/contrib/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java b/contrib/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java index 608d1d936dbe..b461497b96b9 100644 --- a/contrib/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java +++ b/contrib/netbinox/test/unit/src/org/netbeans/modules/netbinox/CountingSecurityManager.java @@ -60,11 +60,7 @@ public enum Mode { public static void initialize(String prefix, Mode mode, Set allowedFiles) { System.setProperty("counting.security.disabled", "true"); - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); setCnt(0); msgs = new StringWriter(); pw = new PrintWriter(msgs); @@ -79,7 +75,6 @@ public static void initialize(String prefix, Mode mode, Set allowedFiles static void assertReflection(int maxCount, String whitelist) { System.setProperty("counting.reflection.whitelist", whitelist); - System.getSecurityManager().checkPermission(new MaxCountPerm(maxCount)); System.getProperties().remove("counting.reflection.whitelist"); } @@ -124,7 +119,7 @@ public Integer call() throws Exception { } public static boolean isEnabled() { - return System.getSecurityManager() instanceof Callable; + return false; } public static void assertCounts(String msg, int expectedCnt) throws Exception { diff --git a/enterprise/performance.scripting/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java b/enterprise/performance.scripting/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java index 652cc2fdb83c..b9f6b674f2c6 100644 --- a/enterprise/performance.scripting/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java +++ b/enterprise/performance.scripting/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java @@ -51,11 +51,10 @@ public static void register() { public static void initialize(String prefix) { Assert.assertNotNull(prefix); - if (! (System.getSecurityManager() instanceof CountingSecurityManager)) { - setAllowedReplace(true); - System.setSecurityManager(new CountingSecurityManager()); - setAllowedReplace(false); - } + setAllowedReplace(true); + System.setSecurityManager(new CountingSecurityManager()); + setAllowedReplace(false); + if (!System.getSecurityManager().getClass().getName().equals(CountingSecurityManager.class.getName())) { throw new IllegalStateException("Wrong security manager: " + System.getSecurityManager()); } diff --git a/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java b/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java index 45b65e53bbb3..361eb697babd 100755 --- a/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java +++ b/ide/ide.kit/test/qa-functional/src/org/netbeans/test/ide/CountingSecurityManager.java @@ -90,11 +90,7 @@ public enum Mode { public static void initialize(String prefix, Mode mode, Set allowedFiles) { System.setProperty("counting.security.disabled", "true"); - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); setCnt(0); msgs = new StringWriter(); pw = new PrintWriter(msgs); @@ -113,7 +109,6 @@ public static void initialize(String prefix, Mode mode, Set allowedFiles static void assertReflection(int maxCount, String whitelist) { System.setProperty("counting.reflection.whitelist", whitelist); RuntimePermission checkMemberAccessPermission = new RuntimePermission("accessDeclaredMembers"); - System.getSecurityManager().checkPermission(checkMemberAccessPermission); System.getProperties().remove("counting.reflection.whitelist"); } @@ -127,7 +122,7 @@ public Integer call() throws Exception { } public static boolean isEnabled() { - return System.getSecurityManager() instanceof Callable; + return false; } public static void assertCounts(String msg, int expectedCnt) throws Exception { diff --git a/ide/projectui/src/org/netbeans/modules/project/ui/groups/CheckBoxRenderrer.java b/ide/projectui/src/org/netbeans/modules/project/ui/groups/CheckBoxRenderrer.java index d0628fd4d406..6a1750ab5233 100644 --- a/ide/projectui/src/org/netbeans/modules/project/ui/groups/CheckBoxRenderrer.java +++ b/ide/projectui/src/org/netbeans/modules/project/ui/groups/CheckBoxRenderrer.java @@ -49,19 +49,11 @@ public CheckBoxRenderrer () { private Border getNoFocusBorder () { Border border = UIManager.getBorder("List.cellNoFocusBorder"); - if (System.getSecurityManager () != null) { - if (border != null) { - return border; - } - return SAFE_NO_FOCUS_BORDER; - } else { - if (border != null && - (noFocusBorder == null || - noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { - return border; - } - return noFocusBorder; + if (border != null && + (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { + return border; } + return noFocusBorder; } public Component getListCellRendererComponent ( diff --git a/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/CheckBoxRenderrer.java b/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/CheckBoxRenderrer.java index 02f7706a8c34..5a434e2987b4 100644 --- a/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/CheckBoxRenderrer.java +++ b/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/CheckBoxRenderrer.java @@ -49,19 +49,11 @@ public CheckBoxRenderrer () { private Border getNoFocusBorder () { Border border = UIManager.getBorder("List.cellNoFocusBorder"); - if (System.getSecurityManager () != null) { - if (border != null) { - return border; - } - return SAFE_NO_FOCUS_BORDER; - } else { - if (border != null && - (noFocusBorder == null || - noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { - return border; - } - return noFocusBorder; + if (border != null && + (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { + return border; } + return noFocusBorder; } public Component getListCellRendererComponent ( diff --git a/ide/versioning/test/unit/src/org/netbeans/modules/versioning/GetOwnerTest.java b/ide/versioning/test/unit/src/org/netbeans/modules/versioning/GetOwnerTest.java index 7b4642306228..ba531213ac0e 100644 --- a/ide/versioning/test/unit/src/org/netbeans/modules/versioning/GetOwnerTest.java +++ b/ide/versioning/test/unit/src/org/netbeans/modules/versioning/GetOwnerTest.java @@ -37,7 +37,6 @@ public class GetOwnerTest extends NbTestCase { protected File dataRootDir; private StatFiles accessMonitor; - private SecurityManager defaultSecurityManager; protected File versionedFolder; protected File unversionedFolder; @@ -69,9 +68,6 @@ protected void setUp() throws Exception { userdir.mkdirs(); System.setProperty("netbeans.user", userdir.getAbsolutePath()); if(accessMonitor != null) { - if(defaultSecurityManager == null) { - defaultSecurityManager = System.getSecurityManager(); - } System.setSecurityManager(accessMonitor); } } @@ -80,7 +76,8 @@ protected void setUp() throws Exception { protected void tearDown() throws Exception { super.tearDown(); if(accessMonitor != null) { - System.setSecurityManager(defaultSecurityManager); + // FIXME - throws UnsupportedOperationException unconditionally, regardless of arg. + System.setSecurityManager(null); } } diff --git a/java/java.navigation/src/org/netbeans/modules/java/stackanalyzer/AnalyserCellRenderer.java b/java/java.navigation/src/org/netbeans/modules/java/stackanalyzer/AnalyserCellRenderer.java index 44d0641fafc6..4b0eb5a52afa 100644 --- a/java/java.navigation/src/org/netbeans/modules/java/stackanalyzer/AnalyserCellRenderer.java +++ b/java/java.navigation/src/org/netbeans/modules/java/stackanalyzer/AnalyserCellRenderer.java @@ -42,17 +42,11 @@ public AnalyserCellRenderer () { private Border getNoFocusBorder() { Border border = UIManager.getBorder("List.cellNoFocusBorder"); - if (System.getSecurityManager() != null) { - if (border != null) return border; - return SAFE_NO_FOCUS_BORDER; - } else { - if (border != null && - (noFocusBorder == null || - noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { - return border; - } - return noFocusBorder; + if (border != null && + (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) { + return border; } + return noFocusBorder; } diff --git a/java/performance.java/test/qa-functional/src/org/netbeans/performance/j2se/actions/CountingSecurityManager.java b/java/performance.java/test/qa-functional/src/org/netbeans/performance/j2se/actions/CountingSecurityManager.java index 64a04837c34d..2bd2017d2ae4 100644 --- a/java/performance.java/test/qa-functional/src/org/netbeans/performance/j2se/actions/CountingSecurityManager.java +++ b/java/performance.java/test/qa-functional/src/org/netbeans/performance/j2se/actions/CountingSecurityManager.java @@ -50,14 +50,10 @@ public static void register() { public static void initialize(String prefix) { Assert.assertNotNull(prefix); - if (! (System.getSecurityManager() instanceof CountingSecurityManager)) { - setAllowedReplace(true); - System.setSecurityManager(new CountingSecurityManager()); - setAllowedReplace(false); - } - if (!System.getSecurityManager().getClass().getName().equals(CountingSecurityManager.class.getName())) { - throw new IllegalStateException("Wrong security manager: " + System.getSecurityManager()); - } + setAllowedReplace(true); + System.setSecurityManager(new CountingSecurityManager()); + setAllowedReplace(false); + cnt = 0; msgs = new StringWriter(); pw = new PrintWriter(msgs); diff --git a/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java b/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java index dcd3b28cead8..17dd919c1a7e 100644 --- a/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java +++ b/java/performance/test/qa-functional/src/org/netbeans/test/ide/PerfCountingSecurityManager.java @@ -91,11 +91,7 @@ public enum Mode { public static void initialize(String prefix, PerfCountingSecurityManager.Mode mode, Set allowedFiles) { System.setProperty("counting.security.disabled", "true"); - if (System.getSecurityManager() instanceof PerfCountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new PerfCountingSecurityManager()); - } + System.setSecurityManager(new PerfCountingSecurityManager()); setCnt(0); msgs = new StringWriter(); pw = new PrintWriter(msgs); @@ -113,7 +109,6 @@ public static void initialize(String prefix, PerfCountingSecurityManager.Mode mo static void assertReflection(int maxCount, String whitelist) { System.setProperty("counting.reflection.whitelist", whitelist); - System.getSecurityManager().checkPermission( SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); System.getProperties().remove("counting.reflection.whitelist"); } @@ -127,7 +122,7 @@ public Integer call() throws Exception { } public static boolean isEnabled() { - return System.getSecurityManager() instanceof Callable; + return false; } public static void assertCounts(String msg, int expectedCnt) throws Exception { diff --git a/java/performance/test/unit/src/org/netbeans/performance/scalability/CountingSecurityManager.java b/java/performance/test/unit/src/org/netbeans/performance/scalability/CountingSecurityManager.java index 0a42eb5166e5..32660829db76 100644 --- a/java/performance/test/unit/src/org/netbeans/performance/scalability/CountingSecurityManager.java +++ b/java/performance/test/unit/src/org/netbeans/performance/scalability/CountingSecurityManager.java @@ -51,14 +51,10 @@ public static void register() { public static void initialize(String prefix) { Assert.assertNotNull(prefix); - if (! (System.getSecurityManager() instanceof CountingSecurityManager)) { - setAllowedReplace(true); - System.setSecurityManager(new CountingSecurityManager()); - setAllowedReplace(false); - } - if (!System.getSecurityManager().getClass().getName().equals(CountingSecurityManager.class.getName())) { - throw new IllegalStateException("Wrong security manager: " + System.getSecurityManager()); - } + setAllowedReplace(true); + System.setSecurityManager(new CountingSecurityManager()); + setAllowedReplace(false); + cnt = 0; msgs = new StringWriter(); pw = new PrintWriter(msgs); diff --git a/platform/core.startup/test/unit/src/org/netbeans/core/startup/CountingSecurityManager.java b/platform/core.startup/test/unit/src/org/netbeans/core/startup/CountingSecurityManager.java index fd6ac88fb244..7b3ef66e437e 100644 --- a/platform/core.startup/test/unit/src/org/netbeans/core/startup/CountingSecurityManager.java +++ b/platform/core.startup/test/unit/src/org/netbeans/core/startup/CountingSecurityManager.java @@ -36,11 +36,7 @@ final class CountingSecurityManager extends SecurityManager { private static String prefix; public static void initialize(String prefix) { - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); cnt = 0; msgs = new StringWriter(); pw = new PrintWriter(msgs); diff --git a/platform/core.startup/test/unit/src/org/netbeans/core/startup/IsDirCntSecurityManager.java b/platform/core.startup/test/unit/src/org/netbeans/core/startup/IsDirCntSecurityManager.java index 12a02eb2aeeb..528704c97d9c 100644 --- a/platform/core.startup/test/unit/src/org/netbeans/core/startup/IsDirCntSecurityManager.java +++ b/platform/core.startup/test/unit/src/org/netbeans/core/startup/IsDirCntSecurityManager.java @@ -32,9 +32,7 @@ public class IsDirCntSecurityManager extends SecurityManager { private static StringBuffer sb; public static void initialize() { - if (!(System.getSecurityManager() instanceof IsDirCntSecurityManager)) { - System.setSecurityManager(new IsDirCntSecurityManager()); - } + System.setSecurityManager(new IsDirCntSecurityManager()); cnt = 0; sb = new StringBuffer(); } diff --git a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java index ed12ee2376c2..1c15dc922996 100644 --- a/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java +++ b/platform/core.startup/test/unit/src/org/netbeans/core/startup/layers/CountingSecurityManager.java @@ -67,11 +67,7 @@ public static void initialize(String prefix, Mode mode, Set allowedFiles System.setProperty("counting.security.disabled", "true"); inSubtree("", ""); - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); setCnt(0); msgs = new StringWriter(); pw = new PrintWriter(msgs); @@ -86,7 +82,6 @@ public static void initialize(String prefix, Mode mode, Set allowedFiles static void assertReflection(int maxCount, String whitelist) { System.setProperty("counting.reflection.whitelist", whitelist); - System.getSecurityManager().checkPermission(new MaxCountCheck(maxCount, "MaxCountCheck")); System.getProperties().remove("counting.reflection.whitelist"); } @@ -129,7 +124,7 @@ public Integer call() throws Exception { } public static boolean isEnabled() { - return System.getSecurityManager() instanceof Callable; + return false; } public static void assertCounts(String msg, int expectedCnt) throws Exception { diff --git a/platform/masterfs/nbproject/project.properties b/platform/masterfs/nbproject/project.properties index 02dca3374ff0..dd2d2d9e88e5 100644 --- a/platform/masterfs/nbproject/project.properties +++ b/platform/masterfs/nbproject/project.properties @@ -31,11 +31,11 @@ test.config.stableBTD.excludes=\ **/FileObjSymlinkTest.class,\ **/FolderObjTest.class,\ **/ChildrenSupportTest.class,\ - **/ProvidedExtensionsTest.class,\ - **/SlowRefreshAndPriorityIOTest.class,\ + **/ProvidedExtensionsTest.class + +test.unit.excludes=\ **/SlowRefreshSuspendableTest.class,\ - **/StatFilesTest.class -spec.version.base=2.90.0 + **/TwoFileNamesForASingleFileTest.class,\ + **/FolderObjCacheTest.class -# TODO remove SM usage in tests -test.jms.flags=-Djava.security.manager=allow +spec.version.base=2.90.0 diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java index 25e775364cba..4910f0691a5d 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshAndPriorityIOTest.java @@ -76,7 +76,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } public void testRefreshCanBeSuspendedByPriorityIO() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java index 473b7d708ee6..5aa05fb4c8d9 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshIncrementalTest.java @@ -73,7 +73,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } public void testChangesDeliveredSoonerThanEverythingIsChecked() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java index 8890e3a62fba..7a1954cd9bf6 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshInterruptibleTest.java @@ -68,7 +68,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } @RandomlyFails // jglick: "No change detected expected:<0> but was:<1>" diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java index dee3be2232ab..ba823edc8f9b 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshPreferrableTest.java @@ -66,8 +66,6 @@ protected void setUp() throws Exception { dir.mkdirs(); testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - - System.setSecurityManager(new FileChangedManager()); } public void testRefreshPrefersSuggestedFolders() throws Exception { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java index d57e76dc7df9..82938cf457e9 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/SlowRefreshSuspendableTest.java @@ -75,7 +75,6 @@ protected void setUp() throws Exception { testFolder = FileUtil.toFileObject(dir); assertNotNull("Test folder created", testFolder); - System.setSecurityManager(new FileChangedManager()); } @RandomlyFails // NB-Core-Build #4386: Background I/O access needs to stop before we finish our task @@ -169,6 +168,8 @@ void doWork() { LOG.log(Level.INFO, "Created {0}", busyFile); for (int i = 0; i < 2000; i ++) { assertTrue("Can be read", busyFile.canRead()); + // SecurityManager checks are not available on recent JDKs. + FileChangedManager.getInstance().checkRead(busyFile.getPath()); LOG.log(Level.INFO, "Touched {0}", i); if (i > 100) { synchronized (this) { diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java index db2738700743..24445e50f12d 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/TwoFileNamesForASingleFileTest.java @@ -45,7 +45,6 @@ public TwoFileNamesForASingleFileTest(String name) { @Override protected void setUp() throws Exception { clearWorkDir(); - System.setSecurityManager(FileChangedManager.getInstance()); } public void testTwoFileNames() throws Exception { @@ -57,6 +56,7 @@ public void testTwoFileNames() throws Exception { assertEquals("Empty is empty", 0, empty.length); final File n = new File(f, "x.txt"); + FileChangedManager.getInstance().checkWrite(n.getPath()); n.createNewFile(); FileObject fn = FileUtil.toFileObject(f); assertNotNull("File object found", fn); @@ -71,8 +71,10 @@ class R implements Runnable { @Override public void run() { refresh(); + FileChangedManager.getInstance().checkDelete(n.getPath()); n.delete(); none = fo.getChildren(); + FileChangedManager.getInstance().checkWrite(n.getPath()); assertTrue("Directory creation succeeds", n.mkdirs()); refresh(); one = fo.getChildren(); diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java index 57b99d0fc373..f7418a746b48 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FolderObjCacheTest.java @@ -36,10 +36,6 @@ * @author Radek Matous */ public class FolderObjCacheTest extends NbTestCase { - static { - System.setSecurityManager(FileChangedManager.getInstance()); - } - Logger LOG; public FolderObjCacheTest(String testName) { @@ -92,6 +88,7 @@ private void doWork(boolean gc) throws IOException { assertNull(FileBasedFileSystem.getFileObject(fold)); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); assertNotNull((workDirFo.getFileSystem()).findResource(workDirFo.getPath()+"/"+fold.getName())); assertNotNull(workDirFo.getFileObject(fold.getName())); @@ -101,6 +98,7 @@ private void doWork(boolean gc) throws IOException { assertTrue(existsChild(workDirFo, fold.getName())); FileObject gcFo = workDirFo.getFileObject(fold.getName()); assertNotNull("One exists", gcFo); + FileChangedManager.getInstance().checkDelete(fold.getPath()); fold.delete(); assertNull("Immediatelly invalidated thanks to FileChangedManager", workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); @@ -113,6 +111,7 @@ private void doWork(boolean gc) throws IOException { } LOG.info("Before mkdir: " + fold); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); LOG.info("After mkdir: " + fold); final FileObject okFn = workDirFo.getFileObject(fold.getName()); @@ -128,6 +127,7 @@ private void doWork(boolean gc) throws IOException { foldFo.delete(); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkWrite(fold.getPath()); fold.mkdir(); //assertNull(((FileBasedFileSystem)workDirFo.getFileSystem()).findFileObject(fold)); //assertNull(MasterFileSystem.getFileObject(fold)); @@ -136,6 +136,7 @@ private void doWork(boolean gc) throws IOException { workDirFo.getFileSystem().refresh(false); assertNotNull(workDirFo.getFileObject(fold.getName())); assertTrue(existsChild(workDirFo, fold.getName())); + FileChangedManager.getInstance().checkDelete(fold.getPath()); fold.delete(); assertNull(workDirFo.getFileObject(fold.getName())); assertFalse(existsChild(workDirFo, fold.getName())); diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java index 9cd126c56ecd..12c804e77581 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/NoLockWhenRefreshIOTest.java @@ -74,7 +74,6 @@ public void testRefreshOfAFolder() throws IOException { FileObject fo = FileUtil.toFileObject(getWorkDir()); FileObject dir = fo.getFileObject("dir"); assertNotNull("dir found", dir); - System.setSecurityManager(new AssertNoLockManager(getWorkDirPath())); List arr = Arrays.asList(dir.getChildren()); dir.refresh(); List arr2 = Arrays.asList(dir.getChildren()); @@ -92,7 +91,6 @@ public void testGetChild() throws IOException { FileObject fo = FileUtil.toFileObject(getWorkDir()); FileObject dir = fo.getFileObject("dir"); assertNotNull("dir found", dir); - System.setSecurityManager(new AssertNoLockManager(getWorkDirPath())); FileObject fileObject = dir.getFileObject("x50.txt"); assertNotNull(fileObject); } diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java index e24bd3c4bd14..2494a753e775 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/StatFilesTest.java @@ -63,7 +63,6 @@ protected void setUp() throws java.lang.Exception { //init FileUtil.toFileObject(testFile); monitor = new StatFiles(); - System.setSecurityManager(monitor); monitor.reset(); } diff --git a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java index 2ad7c8951f3f..4cd6b3e22bf0 100644 --- a/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java +++ b/platform/masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/naming/NamingFactoryTest.java @@ -56,7 +56,6 @@ protected void setUp() throws Exception { } public void registerSecurityManager() { - System.setSecurityManager(new AssertNoLockManager(NamingFactory.class)); } public void testDontForciblyUnregisterFileName() throws Exception { diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/CountingSecurityManager.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/CountingSecurityManager.java index d29eb163aede..7a54ce8b9a73 100644 --- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/CountingSecurityManager.java +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/CountingSecurityManager.java @@ -36,11 +36,7 @@ final class CountingSecurityManager extends SecurityManager { private static String prefix; public static void initialize(String prefix) { - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); cnt = 0; msgs = new StringWriter(); pw = new PrintWriter(msgs); diff --git a/platform/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java b/platform/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java index ab4488d625ec..790f3de109a5 100644 --- a/platform/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java +++ b/platform/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java @@ -390,11 +390,7 @@ private static class BlockingSecurityManager extends SecurityManager { public static void initialize(String path, Semaphore sync) { BlockingSecurityManager.path = path; BlockingSecurityManager.sync = sync; - if (System.getSecurityManager() instanceof BlockingSecurityManager) { - // ok - } else { - System.setSecurityManager(new BlockingSecurityManager()); - } + System.setSecurityManager(new BlockingSecurityManager()); } public @Override void checkRead(String file) { diff --git a/platform/openide.filesystems/nbproject/project.properties b/platform/openide.filesystems/nbproject/project.properties index 6118696e17c5..5e10dfd6f1d3 100644 --- a/platform/openide.filesystems/nbproject/project.properties +++ b/platform/openide.filesystems/nbproject/project.properties @@ -39,9 +39,5 @@ test.config.stableBTD.excludes=\ **/MultiFileSystem3Test.class,\ **/MultiFileSystemXMLTest.class,\ **/RepositoryTest.class,\ - **/StatFilesTest.class,\ **/URLMapperTestHidden.class,\ **/XMLFileSystemTest.class - -# TODO remove SM usage in tests -test.jms.flags=-Djava.security.manager=allow diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java index 029b9db853db..e611d80fc4a6 100644 --- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java +++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java @@ -31,12 +31,12 @@ */ public abstract class TestBaseHid extends MultiThreadedTestCaseHid { /** Support for events*/ - protected List fileChangedL = new ArrayList (); - protected List fileDCreatedL = new ArrayList (); - protected List fileFCreatedL = new ArrayList (); - protected List fileDeletedL = new ArrayList (); - protected List fileRenamedL = new ArrayList (); - protected List fileAttrChangedL = new ArrayList (); + protected List fileChangedL = new ArrayList<>(); + protected List fileDCreatedL = new ArrayList<>(); + protected List fileFCreatedL = new ArrayList<>(); + protected List fileDeletedL = new ArrayList<>(); + protected List fileRenamedL = new ArrayList<>(); + protected List fileAttrChangedL = new ArrayList<>(); private FileChangeListener defListener; private String resourcePrefix = ""; @@ -58,6 +58,7 @@ public TestBaseHid(String name) { * satisfy requirements for resources @see getResources () */ protected FileSystem allTestedFS[]; private static SecurityManager defaultSecurityManager; + /** If not null, file accesses are counted through custom SecurityManager. */ public static StatFiles accessMonitor; @@ -66,7 +67,6 @@ protected void setUp() throws Exception { System.setProperty("workdir", getWorkDirPath()); defListener = createFileChangeListener (); - //FileSystemFactoryHid.destroyFileSystem (this.getName(),this); clearWorkDir(); String[] resources = getResources (getName()); resourcePrefix = FileSystemFactoryHid.getResourcePrefix(this.getName(),this, resources); @@ -74,22 +74,10 @@ protected void setUp() throws Exception { allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this); } if (allTestedFS != null) testedFS = allTestedFS[0]; - // If not null, file accesses are counted through custom SecurityManager. - if(accessMonitor != null) { - if(defaultSecurityManager == null) { - defaultSecurityManager = System.getSecurityManager(); - } - System.setSecurityManager(accessMonitor); - } } @Override protected void tearDown() throws Exception { - // restore SecurityManager if previously changed - if(accessMonitor != null) { - System.setSecurityManager(defaultSecurityManager); - } - if (testedFS instanceof JarFileSystem) { testedFS.removeNotify(); } @@ -109,7 +97,6 @@ protected final void registerDefaultListener (Repository rep) { rep.addFileChangeListener(defListener); } -// private void reinitDefListener() { fileChangedL = new ArrayList (); fileDCreatedL = new ArrayList (); diff --git a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java index 6fab0f33a51a..b884f16a1743 100644 --- a/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java +++ b/platform/openide.filesystems/test/unit/src/org/openide/filesystems/test/StatFiles.java @@ -40,23 +40,15 @@ public class StatFiles extends SecurityManager { public static final int DELETE = 3; private Results results; private Monitor monitor; - private SecurityManager defaultSecurityManager; public StatFiles() { reset(); } public void register() { - if (defaultSecurityManager == null) { - defaultSecurityManager = System.getSecurityManager(); - } - System.setSecurityManager(this); } public void unregister() { - if (defaultSecurityManager == null) { - System.setSecurityManager(defaultSecurityManager); - } } public void reset() { diff --git a/platform/openide.util.ui/test/unit/src/org/openide/xml/XMLUtilReflectionTest.java b/platform/openide.util.ui/test/unit/src/org/openide/xml/XMLUtilReflectionTest.java index 7caedcf8d87c..56b5964ab582 100644 --- a/platform/openide.util.ui/test/unit/src/org/openide/xml/XMLUtilReflectionTest.java +++ b/platform/openide.util.ui/test/unit/src/org/openide/xml/XMLUtilReflectionTest.java @@ -97,11 +97,7 @@ private static void assertSAX(boolean validate, boolean namespace) throws Except static final class CountingSecurityManager extends SecurityManager { public static void initialize() { - if (System.getSecurityManager() instanceof CountingSecurityManager) { - // ok - } else { - System.setSecurityManager(new CountingSecurityManager()); - } + System.setSecurityManager(new CountingSecurityManager()); members.clear(); }