Skip to content

Sandboxed test is not compiling because of illegal unicode escape #1134

Description

@alisevych

Description

Sandboxed test is not compiling because commented stack trace contains "illegal unicode escape".

To Reproduce

  1. Run a project in IntelliJ Idea 2022.1.3 - 2022.2.2
  2. Install RC plugin build
  3. Set Fuzzing to 100% (in File -> Settings -> Tools -> UnitTestBot)
  4. Add the following class (originally posted in Add SecurityManager support to block suspicious code #622 #625 ):
publicclassSecurityCheck {
publicintnormalTest(intvalue) {
if (value < 0) {
return -value;
}
returnvalue;
}
publicintread(Filepath) throwsIOException {
byte[] bytes = Files.readAllBytes(path.toPath());
returnbytes.length;
}
publicintconnect(Socketsocket) throwsIOException {
socket.connect(newInetSocketAddress("0.0.0.0", 22));
return0;
}
publicStringproperty(Stringkey) {
returnSystem.getProperty(key);
}
publicStringsystemExit() {
System.exit(0);
return"bad";
}
}
  1. Generate tests with UnitTestBot
  2. Open generated tests

Expected behavior

Project can be successfully build after test generation.

Actual behavior

SecurityCheckTest is not compiled.
The following error is displayed:

C:\Users\<user_name>\UTBotJava\utbot-sample\src\test\java\org\utbot\examples\securitycheck\SecurityCheckTest.java:2823: error: illegalunicodeescape
/* Thistestfailsbecausemethod [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: accessdenied ("java.io.FilePermission" "jkmqh\uhauh" "read")]

Visual proofs (screenshots, logs, images)

image

There is the following test generated by Fuzzer

///region FUZZER: EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS for method read(java.io.File)@Test@DisplayName("read: path = File(String, String)")
@Disabled(value = "Disabled due to sandbox")
publicvoidtestRead() {
SecurityChecksecurityCheck = newSecurityCheck();
Filepath = newFile("jkmqh", "uhauh");
/* This test fails because method [org.utbot.examples.securitycheck.SecurityCheck.read] produces [java.security.AccessControlException: access denied ("java.io.FilePermission" "jkmqh\uhauh" "read")] java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) java.base/java.security.AccessController.checkPermission(AccessController.java:897) java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322) java.base/java.lang.SecurityManager.checkRead(SecurityManager.java:661) java.base/sun.nio.fs.WindowsChannelFactory.open(WindowsChannelFactory.java:299) java.base/sun.nio.fs.WindowsChannelFactory.newFileChannel(WindowsChannelFactory.java:168) java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230) java.base/java.nio.file.Files.newByteChannel(Files.java:371) java.base/java.nio.file.Files.newByteChannel(Files.java:422) java.base/java.nio.file.Files.readAllBytes(Files.java:3206) org.utbot.examples.securitycheck.SecurityCheck.read(SecurityCheck.java:19) */
}
///endregion

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.2

Additional context

Originally posted by @alisevych in #1125 (comment)

Metadata

Metadata

Labels

ctg-bugIssue is a bug

Type

No type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions