Computer Science 351: Questions and Answers

Frequently asked questions about lab assignments, homeworks, lectures, or any other topic of CS 351 will be posted here.

If you have a question you'd like answered send email to compsci-351@uwm.edu. In your email, please give the following information:

  1. Name of simplest test case that your program fails.
  2. Exact test that fails or errors out. (You can fail a test by giving the wrong answer which assertXXX(...) checks. Or you can fail by crashing with an assertion error or some other exception.)
  3. Exactly what the failure is: which Exception was thrown, or what JUnit says is wrong.
  4. What you think the data structure looks like at the point your code is called. (Tell us whether you have checked your guess in the debugger.)
  5. The snippet of your code (whole method typically) that went wrong. Mark the line where the exception was thrown from, if any.
  6. Explain then either
    1. Why you think your code should do what the test wanted, and why you think it shouldn't crash with that exception, OR
    2. Why you think the test case is doing the wrong thing.
    You are probably wrong in this part, but that's fine. If you weren't wrong, you wouldn't need help!

NB: See Java 8 API.

NB: See how to access your grades.

Homework #2

NB: The TODO comments in Jukebox.java refer to "Sequence" when they should refer to "Song". The two helper comments should say

// TODO: Add note to the END of the song.  (or the song plays backward!)
and
// TODO: For each note in the song
// TODO:   call putNote on the track with the current time stamp
// TODO:   and then increment the timestamp by the ticks (see toTicks)
//         of the note's duration

NB: Hearing some of your questions, we want to emphasize that

"there is no current element"
is different than
"the current element is null"
In the first case, hasCurrent() returns false, and in the second case, it returns true.

Q: WHat do the two "TODO"'s at the top of TestSong.java refer to:

// TDDO: Add some meaningful locked tests
// TODO: Rename tests in numerical order

A: Oops. Some notes to ourselves were left in. Please ignore them.

Q: What is the name of a "catenate"d Song ?

A: Read the javadoc for the method in Song.java to see what it says.

Q: I'm unlocking a later test of a catenated song, and wopnder what the duration of e1 and e2 are.

A: You can see this in setUp. Sorry for not making it obvious in the code before the locked test.

Homework #1

Q: I get an exception and a message about "Usage" when I try to run the musicbox program. How can I run it?

A: The "Usage" says what sort of form your program arguments should be. You need to give a song file (from the songs folder) and other information in the "Program Arguments" section of the "Run Configuration" tab.

Q: I don't know how to implement hash code. What should I do?

A: The hash code should combine integers derived from the fields that are compared for equals. An integer field is usable as is. A double can be converted into an integer for hash code purposes using a method in class Double. When you combine values, the tutorials frequently use "31" to spread the values apart from each other. You may want to use a larger spread. Here's one example tutorial on hash code .

Q: Can we add our own helper methods?

A: In principle yes, but if you do the homework "properly" you shouldn't need to add helper methods, unless we mention them. But if (for example), you don't know the "this(...)" syntax for calling one constructor from another, then a helper method can avoid the need to duplicate code (good to avoid).

Q: For test16 it tells me the expected result is "f#4 x 0.5", but it's failing saying the actual result is "f#4 x 0.5". Why would it fail like this?

A: Under the hood, assertEquals(object1, object2) is checking that object1.equals(object2) returns true. If the test is failing, then these two objects are not being considered equal. Should they be?

Q: Transpose method changes a pitch to a higher or lower octave but it didn't work when I put that as an answer in the test.

A: On the handout:

Note transpose(int)
Return a new note transposed higher (or lower, if the argument is negative) by the given interval (number of MIDI values).
The new note is transposed by the interval based on the MIDI value. If the MIDI value of f#5 is 66, what is the pitch name for MIDI value 67?

Lecture Example

Q: Do we have access to the examples shown in lectures? Where do we find them?

A: You can use eclipse to import the lecture examples using repository path

/afs/cs.uwm.edu/users/classes/cs351/public/lecturen.git
Replace n at the end with the corresponding week number.

Homework Solution

Q: The handout says to check the solution to previous homework for examples. Where do we find them?

A: You can use eclipse to import the solution using repository path

/afs/cs.uwm.edu/users/classes/cs351/solution/homeworkn
Replace n at the end with the corresponding homework number and note that there is no .git at the end. When you try to import the homework solutions using default settings, you may encounter an error that says files already exist. To fix this, there are two things you need to do:
  1. At start up, choose a different workspace
  2. On import dialog, on the step where you can choose the local destination of git repo, type in a different name at the end of the path e.g homework2_solution.
Alternatively, you can ssh into andrew.cs.uwm.edu (see instructions), change directory to the above path.

Accessing AFS through andrew

Q: You said our grades are on AFS and so is the quiz solution. How do we access files in $CLASSHOME/...?

A: You should ssh into andrew.cs.uwm.edu (see instructions). Then you can change directory to the place of interest, e.g. your grade directory or the solution file and look at a file using more.

NB: While on andrew, you can check the status of a homework git, what you have pushed or not:

git --git-dir=/afs/cs.uwm.edu/users/classes/cs351/401/loginname/git/homeworkn.git log

Eclipse Problems

Q: I accidently deleted a file. How can I restore it?

A: There are two ways: one is easier but can only restore an entire directory, the other is more complicated but can restore a single file.

First way, in "Package Explorer", right click on the folder where the deleted file belongs to, and select "Replace With" -> "HEAD Revision". Then click "OK". This will replace ALL files in the directory with the ones in last commit. So if you changed any other file in that directory, make sure commit the change on that file before using this approach.

Second way, select "Git Repository Exploring" from "Window" -> "Open Perspective" in menu bar. Then, look "Git Staging" tab in a sub-window. If you didn't do a commit (you shouldn't!) after having accidently deleted the file, you should see your deleted file in "Stage Changes". Right click the file and choose "Replace with HEAD Revision", the file should be restored.

Q: When I try to "push" I get an error: rejected: non fast-forward.

A: That message means you need to "pull" first before "push".

NB: See instructions to merge if you have any problems with push..

NB: Some easy instructions (PDF) for installing EGit on Eclipse. (Thanks to Brandon Bluemner)

Q: It says I can't run my programs because of a major/minor version error.

A: The problem was that the project was compiled on a machine with a higher version of Java (e.g. 7) than the current setup can handle (often Java 6). Clean the project and try again. ("Project > Clean ..." and then just clean the current project -- the one that doesn't work. No need to clean everything).

NB: A similar problem can happen if you use a non-default JRE in the project. Then nothing works, and you have a nasty red exclamation point on the entire project. You will need to go to Project Properties and choose the Java Build Path and then select the Libraries tab. The JRE library selected is marked as bad, delete and then "Add Library > JRE System Library > Workspace default JRE". Then it will clean automatically and rebuild.

AFS and Kerberos Installation

NB: It is no longer necessary to install OpenAFS on your home computer for CompSci 351

NB: In the instructions that follow, if you are on the campus network, you can use AD.UWM.EDU as the Kerberos realm (cell is still cs.uwm.edu) instead of CS.UWM.EDU and then use your University password.

Installation on Windows (64 bit)

  1. Go to Openafs.org/windows.html
  2. Select the section Kerberos for Windows (MIT or Heimdal)
  3. Select Heimdal Kerberos, which takes you to a webpage at "Secure Endpoints"
  4. Select the latest Heimdal Kerberos (1.5.1 or later) for 64 bit. Run/Install this. (Typical install is fine)
  5. Next, on the same "Secure Endpoints" page, find a link to Network Identity Manager v2 (available separately) and click there.
  6. That brings you to a new page, scroll down to the download section and get the 64 bit regular download (not the SDK download). Run/Install this. (Typical install is fine)
  7. Now assuming you downloaded Heimdahl (not MIT) KfW, on your windows machine, bring up the following file in NotePad running as Administrator:
    C:\ProgramData\Kerberos\krb5.conf
    
    Add a line after the line [libdefaults]. This new line should say
        allow_weak_crypto = true
    
    Then "Save" the file. If it doesn't let you save, then you probably didn't run NotePad as an Administrator. Quit NotePad and try again, this time running NotePad as an Administrator. (Apparently it's possible to run a program as administrator by using Control-Shift-Enter from the Search box under Start. Another possibility is to right-click the notepad application and choose "run as administrator".)
  8. Finally verify that this is working by doing the following in a Command Prompt window:
    kinit yourid@CS.UWM.EDU
    
    Type your CS kerberos password. If on campus, you can use AD.UWM.EDU instead with your panther password. If this succeeds, then continue. Otherwise, tell us the error.
  9. Finally, you can install OpenAFS itself. Go back to the Windows download page for OpenAFS and download the latest 1.7.X distribution. When you run it:
    1. Choose "Typical Install"
    2. On the "Configure AFS Client" Page: Choose "cs.uwm.edu" as the default Cell (NOT openafs.org). And DISABLE "Integrated Logon". Other things should be enabled.
  10. The computer will need to restart. Let it restart and then log in again.
  11. Make sure the network is running (open a browser window).
  12. Start "Network Identity Manager". You might have to look for it.
  13. It will say you don't have credentials. Click to obtain new credentials.
  14. The dialog window will list your Windows logon and ATHENA.MIT.EDU. Change it to your Panther ID (not your student ID!) and CS.UWM.EDU (or, if on campus, AD.UWM.EDU).
  15. If the network is running, it should ask for your password. This is your kerberos password. (or if using AD.UWM.EDU, your panther password).
  16. If it works, you end up with a green credential. A delay of 30 seconds is OK.
  17. If there is a long delay (a minute or more) or a brief error message and THEN the green credential thing comes up, AFS is not working. Perhaps you specified the wrong cell (cs.umw.edu ?). You will need to check the AFS information about your credential. Look at the Advanced view and see if you see something obviously wrong.
  18. Now you can use Eclipse. On Windows, remember to use backslashes. and START with two of them: \\afs\cs.uwm.edu\users\classes\cs351\...
If you have problems, please indicate how far you got through these steps. Also, give the output of the following three commands (run in a Command Prompt window):
  1. net view \\afs
  2. kinit yourpantherid@CS.UWM.EDU
  3. aklog -d -c cs.uwm.edu

NB: If you install Openafs 1.6.X on a Windows machine, don't expect us to be able to help you if it doesn't work. OpenAFS 1.7.X is recommended for all Windows installations.

Installation on MacOSX

  1. Download the software from http://openafs.org/macos.html.
  2. Install the DMG that you have downloaded. ("Click icon to install") "This package will run a program .." (Continue)
  3. On the Client Cell Configuration, select cs.uwm.edu. Optionally cs can be the alias, but you won't need an alias.
  4. Install on the main hard disk. It will ask for your local password to get permission to install.
  5. Then if using Lion or later (e.g., Mountain Lion), open a terminal and use vim (see VIM documentation) to edit /etc/krb5.conf. At the prompt ~ $, type the following
    sudo vi /etc/krb5.conf
    This will ask for the local password, and then bring up the file. Make sure that you have at least the lines:
    [libdefaults]
    allow_weak_crypto = true
    default_realm = CS.UWM.EDU
    
  6. Now you have finished the installation.

    In order to use OpenAFS to access your class files, you will need to get kerberos credentials and use them to get AFS tokens.

    kinit yourpantherid@CS.UWM.EDU
    aklog
    Kerberos credentials (and the associated AFS tokens) expire after a time (typically 10 hours, sometimes 25 hours -- it can be set in your krb5.conf file).

Installation on Linux

If asked the following questions, here are some recommended answers:
AFS cell?
cs.uwm.edu
size of AFS cache?
1000000 (that is, one gigabyte)
run AFS now?
yes
encrypt AFS traffic?
yes
dynamically generate contents of /afs?
yes
fakestate?
yes
You should ensure that /var/openafs/cache has at least as much space free as you promise in your cache response. Best is that the cache is its own partition. The file system should be ext2, ext3 or ext4. Once you have installed it, continue with the instructions for MacOSX.

Troubleshooting an AFS/kerberos installation

Some OpenAFS errors are easy to fix. Use aklog -d in a command prompt / terminal window to determine the problem.

Error 56 (Authentication server unavailable)
This means you are trying to use the AFS client service to get tickets. This doesn't work. You have to use Network Identity Manager (Windows) and/or aklog (any).
No credentials cache file found
You haven't got Kerberos tickets with Network Identity Manager yet. First get tickets and then if the Advanced view doesn't show AFS tokens, then run aklog again.
enryption type des-cbc-crc disabled
You need to edit krb5.conf to allow weak cryptography as described above.
KDC has no support for encryption type
You need to edit krb5.conf to allow weak cryptography as described above.
error -1765328234
You need to edit krb5.conf to allow weak cryptography as described above.
missing XXX.dll
This means you installed MIT kerberos for windows 32 bit but are on a 64 bit machine. You should have gotten the 64 bit version from Secure Endpoints. Look carefully for the 64 bit link on the OpenAFS installation page. Uninstall the old NIM and re-install the correct one.
clock skew
This means your system clock is more than 5 minutes off the AFS server. You should make sure you have the right time zone (US Central) and then reset your system clock to agree with an external source, e.g. your cell phone.
Couldn't get openafs.org AFS tickets
If you get an error message about openafs.org, this means you accepted the default cell as openafs.org instead of changing it to cs.uwm.edu. I don't know how to change it after installation (you could uninstall and reinstall and this time make sure to set the default cell), but you can also run aklog with a cell option:
aklog -d -c cs.uwm.edu
The Network Identity Manager also has a way to get tickets from cells other than the default cell. It's in a hidden dialog. Go to the Options>AFS page, and then select your panther ID (half way up the page) and then select the AFS tab, and then add cs.uwm.edu as a cell to use in the bottom dialog.
ktc 7
If you had OpenAFS working, and it stops working, and this is the error, it can be fixed by rebooting. Otherwise, this is a hard error to fix. This error no longer happens with the OpenAFS 1.7.X IFS client.
RPC server is unavailable
If this error happens when you try to navigate to \\afs\cs.uwm.edu this means your computer is not letting you access the AFS server. You probably have an overactive firewall.
client not found in kerberos database
You are using the wrong realm. You should use CS.UWM.EDU or AD.UWM.EDU, not a lowercase name or MIT.EDU etc.

NB: On Linux or MacOSX, the command line is used to authenticate to AFS. On Miller, I wrote a script called klog. You can make yourself a similar script. The only two things you MUST have are

kinit PantherID@CS.UWM.EDU
aklog -c cs.uwm.edu

Q: On my Windows Vista PC, I can get a kerberos ticket, but don't get permission to access CS 351 files.

A: You need an AFS token. The network identity manager defaults to openafs.org, but you need to change that (File>AFS>Preferences) to cs.uwm.edu. Then add 'cs.uwm.edu' as a cell to automatically get tickets for. Once you have a kerberos ticket, it will get your AFS tokens for you.

Q: How do I get to the CS 351 from my windows PC?

A: Use the ANC path: \\afs\cs.uwm.edu\users\classes\cs351\...

Q: On my MAC/Linux computer, when I try to kinit, it says

client not found in the kerberos database.
A: This means the default realm is not CS.UWM.EDU, and so you have to specify it on the command line, or make it the default realm.

Q: If I get past the error I just mentioned, I get a new error:

Cannot get any kdc for realm CS.UWM.EDU
A: This means that your computer is prevented from accessing the KDC. This can happen if you are off the network, or have a paranoid firewall, or are using UWM's "Public" WiFi system.

Q: What should krb5.conf have in it?

A: Actually you don't need to have much of anything, unless you are using Heimdahl in which case you must "allow weak crypto" but the following is a reasonable contents:

[libdefaults]
allow_weak_crypto = true
default_realm = CS.UWM.EDU

[realms]
CS.UWM.EDU = {
  kdc = kerberos.cs.uwm.edu
  kdc = kerberos-1.cs.uwm.edu
  master_kdc = kerberos.cs.uwm.edu
  admin_server = kerberos.cs.uwm.edu
}

Q: On my Mac, I got the kerberos tickets; now how do I get AFS access.

A: Use "aklog" from a terminal window, or use one of the Third Party tools mentioned on the OpenAFS download page for MacOSX.


CS 351 FAQ / John Tang Boyland boyland@cs.uwm.edu