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
10 changes: 9 additions & 1 deletion approximations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
java
`maven-publish`
id("org.springframework.boot") version "3.2.0" apply false
}

repositories {
Expand All @@ -9,12 +10,17 @@ repositories {
}

private val jacodbPackage = "com.github.UnitTestBot.jacodb"
private val jacodbVersion = "890624770b" // jacodb neo branch
private val jacodbVersion = "00164e304b" // jacodb neo branch

dependencies {
compileOnly("$jacodbPackage:jacodb-api-jvm:$jacodbVersion")
compileOnly("$jacodbPackage:jacodb-approximations:$jacodbVersion")
compileOnly(files(rootDir.resolve("usvm-api/usvm-api.jar")))
compileOnly("org.springframework.boot:spring-boot-starter-web:3.2.0")
compileOnly("org.springframework.boot:spring-boot-starter-test:3.2.0")
compileOnly("org.springframework.boot:spring-boot-starter-data-jpa:3.2.0")
// Fixes "unknown enum constant 'When.MAYBE'" warning
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
}

group = "org.usvm.approximations.java.stdlib"
Expand All @@ -28,6 +34,8 @@ tasks.withType<JavaCompile> {
options.compilerArgs.add("-source")
options.compilerArgs.add("1.8")
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Werror")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Collections;
import java.util.List;

@SuppressWarnings("ForLoopReplaceableByForEach")
@SuppressWarnings({"ForLoopReplaceableByForEach", "removal"})
@DecoderFor(SecurityManager.class)
public final class SecurityManager_Decoder implements ObjectDecoder {
private volatile JcMethod cached_SecurityManager_ctor = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
decoder.invokeMethod(m_add, args);

map.remove(key);
length -= 1;
length--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
decoder.invokeMethod(m_add, args);

map.remove(key);
length -= 1;
length--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public <T> T createInstance(final JcClassOrInterface approximation,

if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}

Expand Down Expand Up @@ -92,4 +92,4 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
final DecoderApi<T> decoder) {
// nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public <T> T createInstance(final JcClassOrInterface approx,
// NOTE: this is an example on how to join discovery process for multiple targets
if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}
if (f_value != null && f_present != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public <T> T createInstance(final JcClassOrInterface approx,

if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package encoders.java.util;

import generated.java.util.map.AbstractMap_EntryImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;
import stub.java.util.map.AbstractMap_Entry;

import java.util.Map;

@EncoderFor(AbstractMap_Entry.class)
public class AbstractMap_Entry_Encoder implements ObjectEncoder {

@Override
public Object encode(Object list) {
return new AbstractMap_EntryImpl<>((Map.Entry<?, ?>) list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package encoders.java.util;

import generated.java.util.list.ArrayListImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.ArrayList;

@EncoderFor(ArrayList.class)
public class ArrayList_Encoder implements ObjectEncoder {

@Override
public Object encode(Object list) {
ArrayListImpl<Object> result = new ArrayListImpl<>();
result.addAll(((ArrayList<?>) list).stream().toList());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package encoders.java.util;

import generated.java.util.map.ConcurrentHashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.concurrent.ConcurrentHashMap;

@EncoderFor(ConcurrentHashMap.class)
public class ConcurrentHashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
ConcurrentHashMap<Object, Object> map = (ConcurrentHashMap<Object, Object>) object;
return new ConcurrentHashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package encoders.java.util;

import generated.java.util.map.HashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.HashMap;

@SuppressWarnings("unused")
@EncoderFor(HashMap.class)
public class HashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
HashMap<Object, Object> map = (HashMap<Object, Object>) object;
return new HashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package encoders.java.util;

import generated.java.util.set.HashSetImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@EncoderFor(HashSet.class)
public class HashSet_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
HashSetImpl<Object> result = new HashSetImpl<>();
result.addAll(Arrays.asList(((Set<?>) object).toArray()));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package encoders.java.util;

import generated.java.util.map.LinkedHashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.LinkedHashMap;

@SuppressWarnings("unused")
@EncoderFor(LinkedHashMap.class)
public class LinkedHashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
LinkedHashMap<Object, Object> map = (LinkedHashMap<Object, Object>) object;
return new LinkedHashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package encoders.java.util;

import generated.java.lang.StringImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

@EncoderFor(java.lang.String.class)
public class String_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
return new StringImpl(((String) object).getBytes());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package encoders.java.util;

import generated.java.lang.ThreadLocalImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

@EncoderFor(java.lang.ThreadLocal.class)
public class ThreadLocal_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
return new ThreadLocalImpl<>();
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
// Generated by the LibSL translator. DO NOT EDIT!
// sources:
// - java/lang/AutoCloseable.lsl:26
// - java/lang/AutoCloseable.main.lsl:16
//
package generated.java.lang;

import java.lang.Class;
import java.lang.SuppressWarnings;
import java.lang.Void;
import org.jacodb.approximation.annotation.Approximate;
import org.usvm.api.Engine;
import runtime.LibSLRuntime;

/**
* AutoCloseableAutomaton for LSLAutoCloseable ~> java.lang.AutoCloseable
*/
@SuppressWarnings({"all", "unchecked"})
@SuppressWarnings("unused")
@Approximate(java.lang.AutoCloseable.class)
public interface AutoCloseable extends LibSLRuntime.Automaton {
Class __$_lsl_INIT_INTERFACE_AutoCloseableAutomaton_d61c3b46 = Void.class;
public interface AutoCloseable {

/**
* [FUNCTION] AutoCloseableAutomaton::close(LSLAutoCloseable) -> void
* Source: java/lang/AutoCloseable.main.lsl:39
*/
default void close() {
/* body */ {
}
}

final class __$lsl_States {
public static final byte Initialized = (byte) 0;
}

@Approximate(AutoCloseable.class)
final class __hook {
private __hook(Void o1, Void o2) {
Engine.assume(false);
}
}
default void close() { }
}
Loading