Environment: Introduction to Java class programming labs.
Is it possible to force Java to throw an exception if any imports for banned classes are used? For example, I have a lab where I specifically want them to calculate some geometry and I do not want them to just use built-in libraries.
Current solution: Grep all the java files for banned keywords. This works after the fact. I would like their code to fail on compile so they don't turn in work.
My theory is that they have to make their main class extend from a "project" class that I provide. The project class blocks access to banned libraries - if possible.
Java has built in mechanisms for preventing classes from being loaded, namely the SecurityManager. It won't make the code fail to compile, but it would fail to run with an exception.
Create the SecurityManager for your needs and call to the students' projects. If they are using banned libraries, it will throw an exception.
Reference: https://docs.oracle.com/javase/tutorial/essential/environment/security.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With