Skip to content
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

Local and server-side tests can't run with newer Java syntax since source version is set to 1.6 instead of 7 #138

Closed
matjojo opened this issue Jun 4, 2018 · 2 comments

Comments

@matjojo
Copy link

matjojo commented Jun 4, 2018

NOTE: this isn't really an issue with the plugin but more with the assignments that are downloaded using the plugin, if anyone could point me to where I should report issues with the assignments that would be great.

Since server-side tests don't work anymore either (will create issue after this) I wanted to run the local tests until I knew for sure the program was right, to make sure that the problem was not in reading the returned data from the server but in the server testing process.
To reproduce:

  1. got to assignment 103 from Part one (week 6)
  2. add a correct answer:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // implement your program here
    // do not put all to one method/class but rather design a proper structure to your program
        
    // Your program should use only one Scanner object, i.e., it is allowed to call 
    // new Scanner only once. If you need scanner in multiple places, you can pass it as parameter

        ArrayList<Bird> database = new ArrayList<>();

        Scanner reader = new Scanner(System.in);
        String command;
        String newName;
        String newLatinName;
        String searchName;
        Boolean isBird;
        loop:
        while (true) {
            System.out.print("? ");
            isBird = false;

            command = reader.nextLine();

            switch (command) {
                case "Add": {
                    System.out.print("name: ");
                    newName = reader.nextLine();
                    System.out.print("Latin Name: ");
                    newLatinName = reader.nextLine();
                    database.add(new Bird(newName, newLatinName));
                    break;
                }
                case "Observation": {
                    System.out.print("What was observed:? ");
                    searchName = reader.nextLine();
                    for (Bird bird : database) {
                        if (bird.getName().equals(searchName)) {
                            bird.observe();
                            isBird = true;
                        }
                    }
                    if (!isBird) {
                        System.out.println("Is not a bird!");
                    }
                    break;
                }
                case "Statistics": {
                    for (Bird bird :
                            database) {
                        System.out.println(bird);
                    }
                    break;
                }
                case "Show": {
                    System.out.print("What? ");
                    searchName = reader.nextLine();
                    for (Bird bird :
                            database) {
                        if (bird.getName().equals(searchName)) {
                            isBird = true;
                            System.out.println(bird);
                        }
                        if (!isBird) {
                            System.out.println("Is not a bird!");
                        }
                    }
                    break;
                }
                case "Quit": {
                    break loop;
                }
                default: {
                    System.out.println("Invalid command!");
                    break;
                }
            }
        }
    }
}

  1. And in bird,java:
public class Bird {
    private String name;
    private String latinName;
    private int observations;

    public Bird(String name, String latinName) {
        this.name = name;
        this.latinName = latinName;
    }

    public String getName() {
        return this.name;
    }

    public void observe() {
        this.observations++;
    }

    public String toString() {
        String printable = "";
        printable += this.name;
        printable += (" " + "(" + this.latinName + ")");
        printable += (": " + String.valueOf(this.observations) + " observations");
        return printable;
    }


}

  1. Try to run the local tests
  2. They error saying this:
C:\Users\matth\Documents\IdeaProjects\TMCProjects\mooc-2013-OOProgrammingWithJava-PART1\week6-103.Birdwatcher\nbproject\build-impl.xml:603: The following error occurred while executing this line:
C:\Users\matth\Documents\IdeaProjects\TMCProjects\mooc-2013-OOProgrammingWithJava-PART1\week6-103.Birdwatcher\nbproject\build-impl.xml:245: Compile failed; see the compiler error output for details.

Total time: 1 second

and the compiler error output:

-do-compile:
    [javac] Compiling 1 source file to C:\Users\matth\Documents\IdeaProjects\TMCProjects\mooc-2013-OOProgrammingWithJava-PART1\week6-103.Birdwatcher\build\classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] C:\Users\matth\Documents\IdeaProjects\TMCProjects\mooc-2013-OOProgrammingWithJava-PART1\week6-103.Birdwatcher\src\Main.java:13: error: diamond operator is not supported in -source 1.6
    [javac]         ArrayList<Bird> database = new ArrayList<>();
    [javac]                                                  ^
    [javac]   (use -source 7 or higher to enable diamond operator)
    [javac] 1 error
    [javac] 1 warning

To fix:

  1. Go to /nbproject/project.properties:48
  2. Change javac.source and javac.target from 1.6 to 7 (for new enough syntax to include this diamond operator and String objects in case switches)
  3. Run the tests again.

They now work.

To me this seems like a problem with how the assignments where created, but I have no idea where in this project they are created, if I should have made this issue somewhere else please tell me.

@matjojo matjojo changed the title Local tests can't run with newer Java syntax since source version is set to 1.6 instead of 7 Local and server-side tests can't run with newer Java syntax since source version is set to 1.6 instead of 7 Jun 4, 2018
@matjojo
Copy link
Author

matjojo commented Jun 4, 2018

I went to the server to see if the server could give any extra information on why the server-side tests where failing, and I could see an error code exactly the same as the local error I just fixed:

-do-compile:
    [mkdir] Created dir: /app/build/empty
    [mkdir] Created dir: /app/build/generated-sources/ap-source-output
    [javac] Compiling 2 source files to /app/build/classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] /app/src/Main.java:13: error: diamond operator is not supported in -source 1.6
    [javac]         ArrayList<Bird> database = new ArrayList<>();
    [javac]                                                  ^
    [javac]   (use -source 7 or higher to enable diamond operator)
    [javac] 1 error
    [javac] 1 warning

stderr: 
BUILD FAILED
/app/nbproject/build-impl.xml:603: The following error occurred while executing this line:
/app/nbproject/build-impl.xml:245: Compile failed; see the compiler error output for details.

Total time: 3 seconds

Seems to me like the same problem I had locally is also the problem on the server. The standard project.properties files need to be edited to allow newer source versions.

again:
I have no idea where in this project these files are created, if I should have made this issue somewhere else please tell me.

Extra verification that this is indeed the problem:

  1. Change the diamond operator in my solution to an explicit Bird type and see this error on the server appear:
-do-compile:
    [mkdir] Created dir: /app/build/empty
    [mkdir] Created dir: /app/build/generated-sources/ap-source-output
    [javac] Compiling 2 source files to /app/build/classes
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] /app/src/Main.java:28: error: strings in switch are not supported in -source 1.6
    [javac]             switch (command) {
    [javac]                    ^
    [javac]   (use -source 7 or higher to enable strings in switch)
    [javac] 1 error
    [javac] 1 warning

stderr: 
BUILD FAILED
/app/nbproject/build-impl.xml:603: The following error occurred while executing this line:
/app/nbproject/build-impl.xml:245: Compile failed; see the compiler error output for details.

Total time: 3 seconds

link to this error report

So it's not just the diamond operator, it's also a problem with strings in switches.

@nygrenh
Copy link
Member

nygrenh commented Jun 4, 2018

Moving this here: materiaalit/2013-oo-programming#1

See testmycode/tmc-server#486

@nygrenh nygrenh closed this as completed Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants