Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.utbot.engine.overrides;

import org.utbot.api.annotation.UtClassMock;

import java.security.AccessControlContext;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

@UtClassMock(target = java.security.AccessController.class, internalUsage = true)
public class AccessController {
public static <T> T doPrivileged(PrivilegedAction<T> action) {
return action.run();
}

public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
return action.run();
}

public static <T> T doPrivileged(PrivilegedAction<T> action,
AccessControlContext ignoredContext) {
return action.run();
}

public static <T> T doPrivileged(PrivilegedAction<T> action,
AccessControlContext ignoredContext, Permission... perms) {
if (perms == null) {
throw new NullPointerException();
}

for (Permission permission : perms) {
if (permission == null) {
throw new NullPointerException();
}
}

return action.run();
}

public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
AccessControlContext context, Permission... perms) {
return doPrivileged(action, context, perms);
}

public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException {
try {
return action.run();
} catch (RuntimeException e) {
// If the action's run method throws an unchecked exception, it will propagate through this method.
throw e;
} catch (Exception e) {
// Exception is wrapped with the PrivilegedActionException ONLY if this exception is CHECKED
throw new PrivilegedActionException(e);
}
}

public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) throws PrivilegedActionException {
return doPrivileged(action);
}

public static <T> T doPrivileged(
PrivilegedExceptionAction<T> action,
AccessControlContext ignoredContext
) throws PrivilegedActionException {
return doPrivileged(action);
}

public static <T> T doPrivileged(
PrivilegedExceptionAction<T> action,
AccessControlContext ignoredContext,
Permission... perms
) throws PrivilegedActionException {
if (perms == null) {
throw new NullPointerException();
}

for (Permission permission : perms) {
if (permission == null) {
throw new NullPointerException();
}
}

return doPrivileged(action);
}

public static <T> T doPrivilegedWithCombiner(
PrivilegedExceptionAction<T> action,
AccessControlContext context,
Permission... perms
) throws PrivilegedActionException {
return doPrivileged(action, context, perms);
}

public static void checkPermission(Permission perm) {
if (perm == null) {
throw new NullPointerException();
}

// We cannot check real permission do determines whether we should throw an AccessControlException,
// so do nothing more.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.utbot.engine.overrides;

import org.utbot.api.annotation.UtClassMock;

@UtClassMock(target = java.lang.AutoCloseable.class, internalUsage = true)
public interface AutoCloseable {
default void close() throws Exception {
// Do nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.utbot.engine.overrides;

import org.utbot.api.annotation.UtClassMock;
import org.utbot.api.mock.UtMock;

@UtClassMock(target = java.lang.Throwable.class, internalUsage = true)
public class Throwable {
public void printStackTrace() {
// Do nothing
}

public synchronized java.lang.Throwable fillInStackTrace() {
return UtMock.makeSymbolic();
}

public StackTraceElement[] getStackTrace() {
return UtMock.makeSymbolic();
}

public void setStackTrace(StackTraceElement[] stackTrace) {
// Do nothing
}

public final synchronized void addSuppressed(java.lang.Throwable exception) {
// Do nothing
}

public final synchronized java.lang.Throwable[] getSuppressed() {
return UtMock.makeSymbolic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ private val classesToLoad = arrayOf(
org.utbot.engine.overrides.Long::class,
org.utbot.engine.overrides.Short::class,
org.utbot.engine.overrides.System::class,
org.utbot.engine.overrides.Throwable::class,
org.utbot.engine.overrides.AutoCloseable::class,
org.utbot.engine.overrides.AccessController::class,
org.utbot.engine.overrides.collections.UtOptional::class,
org.utbot.engine.overrides.collections.UtOptionalInt::class,
org.utbot.engine.overrides.collections.UtOptionalLong::class,
Expand Down