Skip to content

Pelevin/improve java fuzzing type system #1594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 28, 2022

Conversation

Markoutte
Copy link
Collaborator

Description

Adds implementation for Iterator<*> type and improve type system to support recursive or dependent types like:

public static  <T extends Iterator<T>> int size(T some)

Type of Change

Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Automated Testing

org.utbot.fuzzing.JavaFuzzingTest

Manual Scenario

Try to generate tests with only fuzzing for these functions:

public static  <T extends Iterator<T>> int size(T some) {
        int r = 0;
        while (some.hasNext()) {
            T next = some.next();
            while (next != null && next.hasNext()) {
                T n2 = next.next();
                while (n2 != null && n2.hasNext()) {
                    n2.next();
                    r++;
                }
                r++;
            }
            r++;
        }
        return r;
    }
public class ManyRecursiveCalls<T extends Map<String, Number>> {

    private final T[] value;


    public ManyRecursiveCalls(T[] value) {
        this.value = value;
    }

    public double getSum() {
        double sum = 0;
        for (T numbers : value) {
            for (Number number : numbers.values()) {
                if (number.doubleValue() > 0) {
                    sum += number.doubleValue();
                }
            }
        }
        if (sum == 0.0) {
            throw new IllegalStateException();
        }
        return sum;
    }
}

Checklist (remove irrelevant options):

This is the author self-check list

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

@Markoutte Markoutte requested a review from volivan239 December 27, 2022 04:51
Copy link
Collaborator

@volivan239 volivan239 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For third type parameter of the method below, toFuzzerType returns a finite type (see image below). Is this the expected behavior?

public static <A extends Iterable<B>, B extends List<A>, C extends List<? extends Iterable<A>>> A example(A c1, B c2, C c) {
    return c2.iterator().next();
}

image

Comment on lines 177 to 179

private fun Type.findRealTypeUntilTypeVariable() : Type {
var type: Type = this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the method is misleading, I think it should be something like Type.replaceWithUpperBoundUntilNotTypeVariable, also docs would be great here

Copy link
Collaborator Author

@Markoutte Markoutte Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the example! No, this is not expected, fixed

@Markoutte Markoutte requested a review from volivan239 December 28, 2022 07:29
@Markoutte Markoutte merged commit b049951 into main Dec 28, 2022
@Markoutte Markoutte deleted the pelevin/improve_java_fuzzing_type_system branch December 28, 2022 12:21
@tyuldashev tyuldashev added ctg-enhancement New feature, improvement or change request comp-fuzzing Issue is related to the fuzzing labels Jan 24, 2023
@alisevych alisevych added this to the 2023.03 Release milestone Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants