Skip to content

Unused import of java.net.UnknownHostException #1999

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

Open
alisevych opened this issue Mar 21, 2023 · 0 comments
Open

Unused import of java.net.UnknownHostException #1999

alisevych opened this issue Mar 21, 2023 · 0 comments
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-java Issue is related to Java support

Comments

@alisevych
Copy link
Member

alisevych commented Mar 21, 2023

Description

Unused import of java.net.UnknownHostException

To Reproduce

  1. Run the 'utbot' project in IntelliJ Idea 2022.2.4 Ultimate
  2. Install plugin built from unit-test-bot/rc3102023 branch
  3. Set Fuzzing 100% in Settings -> Tools -> UnitTestBot
  4. Generate tests for the following code:
public class SecurityCheck {
    public int connect(Socket socket) throws IOException {
        socket.connect(new InetSocketAddress("0.0.0.0", 22));
        return 0;
    }
}

Expected behavior

There should be no unused imports.

Actual behavior

There is import java.net.UnknownHostException that is not used in test code.

Visual proofs (screenshots, logs, images)

The following test is generated by Fuzzing:

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

import java.net.Socket;
import java.net.UnknownHostException;
import java.io.IOException;

public final class SecurityCheckTest {
    ///region Test suites for executable SecurityCheck.connect

    ///region FUZZER: SECURITY for method connect(java.net.Socket)

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket()")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect() {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket();
        
        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:22" "connect,resolve")]
            java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
            java.security.AccessController.checkPermission(AccessController.java:886)
            java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
            java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
            java.net.Socket.connect(Socket.java:608)
            java.net.Socket.connect(Socket.java:561)
            SecurityCheck.connect(SecurityCheck.java:22) */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect1() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("abc", Integer.MIN_VALUE);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "abc" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect2() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("", 0, true);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect3() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("\u0086", 0, true);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "�" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect4() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("\u0086", Integer.MIN_VALUE, true);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "�" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect5() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("0.0.0.0", 0, false);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:0" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect6() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("abc", 0);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "abc" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect7() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket("", 0);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link SecurityCheck}
     * @utbot.methodUnderTest {@link SecurityCheck#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @org.junit.jupiter.api.Disabled(value = "Disabled due to sandbox")
    public void testConnect8() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        Socket socket = new Socket(":", 0);

        /* This test fails because method [SecurityCheck.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "[:]:0" "connect,resolve")] */
    }
    ///endregion

    ///region Errors report for connect

    public void testConnect_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 6099 occurrences of:
        // Default concrete execution failed

    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.4 Ultimate

Originally posted by @alisevych in #1314 (comment)

@alisevych alisevych added ctg-bug Issue is a bug comp-codegen Issue is related to code generator lang-java Issue is related to Java support labels Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-java Issue is related to Java support
Projects
Status: Todo
Development

No branches or pull requests

2 participants