Java: Add Guard Classes for checking OS

This commit is contained in:
Jonathan Leitschuh
2022-02-14 15:23:08 -05:00
parent b39f383d45
commit cd073a2173
8 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class Test {
void test() {
if (System.getProperty("os.name").contains("Windows")) {
}
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
}
if (System.getProperty("os.name").contains("Linux")) {
}
if (System.getProperty("os.name").contains("Mac OS X")) {
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
}
if (Path.of("whatever").getFileSystem().supportedFileAttributeViews().contains("posix")) {
}
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
}
}
}

View File

@@ -0,0 +1,5 @@
| Test.java:14:13:14:59 | contains(...) |
| Test.java:18:13:18:62 | contains(...) |
| Test.java:22:13:22:71 | contains(...) |
| Test.java:26:13:26:95 | contains(...) |
| Test.java:30:13:30:84 | contains(...) |

View File

@@ -0,0 +1,5 @@
import default
import semmle.code.java.os.OSCheck
from IsUnixGuard isUnix
select isUnix

View File

@@ -0,0 +1,2 @@
| Test.java:6:13:6:61 | contains(...) |
| Test.java:10:13:10:75 | contains(...) |

View File

@@ -0,0 +1,5 @@
import default
import semmle.code.java.os.OSCheck
from IsWindowsGuard isWindows
select isWindows