BlueJ with Modified Error Subsystem
Warren Toomey, October 2011
Novice programmers often make simple errors, but they don't receive
very good advice on how to fix the errors from the development tools
such as the compiler: obscure reports such as "char cannot be
dereferenced", for example, give no useful guidance to the student.
This is a modified version of BlueJ which has had the error reporting
subsystem rewritten to:
- find common programming errors that novice programmers make,
- report these errors back in a descriptive way to reiterate the core
concepts of programming, and
- give advice that the student can follow to fix the problem.
This is a follow-on to the proof of concept version, Arjen,
that Jon Gjengset and I wrote in 2010.
Changelog
- 2011 Nov 12, wkt1.4: Merged the BlueJ 3.0.6 changes. New errors: bad
type for unary operator, cannot find constructor, orphaned 'default',
duplicate method in the same class.
- 2011 Oct 31, wkt1.3: More errors: incorrect comparison operators '=>'
and '=<', how to find the Scanner class, can't use length() on an
array, can't compare whole arrays to values, can't assign a value
to a whole array and vice versa.
- 2011 Oct 29, wkt1.2: Modifications to the parser to catch these new
errors: malformed 'For' loops, bad String comparisons using '==',
and changing the value of the loop variable inside the body of a 'For'
loop.
- 2011 Oct 24, wkt1.1: First release of the modified error subsystem
for BlueJ 3.0.5.
Screenshots
Also see this YouTube video.
Installation
Download one of the following installers and follow the BlueJ installation instructions.
The modified BlueJ installer also comes with an extension that logs
the errors made during compilation. If you don't want this functionality,
find and remove the errorlog.jar file which is located in bluej/lib/extensions.
Alternatively, download the source code to this extension below and
modify it to suit your situation.
Building BlueJ with the Changes
The changes to the BlueJ source code are provided in a Zip file below.
To apply the changes, firstly download the original BlueJ source code.
Unzip the Zip file. Download the Zip file with the changes and unzip
it in the same location to apply the changes. You should then be able
to run "ant build" to build the modified BlueJ.
Description of the Changes
This modified version of BlueJ has these new features:
- Before a Java source file is compiled, it is first parsed, and some
parse errors are reported to the user. This allows certain errors
to be reported which the compiler would not find, e.g. empty statements,
String comparisons using '=='.
- Both the titles and the descriptions of the errors can now be internationalised.
The title of an error is no longer dependent on the compiler's error
message.
- Words found in the compiler or parse error can now be extracted and
placed in the title and the description of an error. This helps to
contextualise the error messages.
- The set of recognised errors is now stored in a data file outside
BlueJ. This allows the installer to choose which errors BlueJ reports.
For example, an introductory programming subject may wish to treat
the use of bitwise operators ( & and | ) as an error, but
other subjects may wish to permit the use of these operators.
- Certain warnings issued by the compiler can now be promoted into errors.
There is now a new data file called "errorlist.defs", stored
in the per-language folder (e.g. "english/"). At compile time,
lines from this file are used to interpret the errors from the parser,
the compiler, or from inspection of the source code being compiled.
Each line has three fields, separated by double colons. The first
field contains one of four values:
- "parsewarn": a message from the parser which is treated as a
warning.
- "parseerr": a message from the parser which is treated as an
error.
- "compwarn": a message from the compiler which is treated as
a warning.
- "comperr": a message from the compiler which is treated as an
error.
The second field is the title of the error or warning, written in
a human language and which does not have to relate to the message
from the compiler or parser.
The third field is a regular expression which recognises the error
or warning sent from the parser or compiler.
The new error subsystem applies the lines from "errorlist.defs"
in turn. When the first match occurs, the subsystem takes the title
(the second field on the line) and looks up the description of the
error in the "javac.help" file, also in the language-specific
folder.
In the regular expression, capture patterns ( ) can collect words
or identifiers from the parser/compiler/code input. These will then
be passed to the user through the use of %s formatting in both the
error title in "errorlist.defs" and the error description in
"javac.help".
To stop the recognition of specific errors, the matching lines can
either be removed from the "errorlist.defs" file, or these lines
can be commented out using // Java-style comments.
Example Errors
Above, there is a Zip file with all the known errors. In each text
file is the line to put in "errorlist.defs", the description
which goes in "javac.help", plus a Perl program to create "errorlist.defs"
and "javac.help" from these files. Some of the text files contain
Java source which exhibits the error. You can browse the example Java files on-line.
I would love to collect more example Java files for the known errors,
and also textual descriptions for the errors which have no textual
descriptions.
Internationalisation
At present, only an English version of "errorlist.defs" and
"javac.help" has been created. I would very much like to get
translations of these into other languages.
Comments/Feedback
If you have any questions or comments about the changes I've made,
please e-mail them to me at wkt at tuhs dot org, or post your
comment/question in this Blueroom forum.
File translated from
TEX
by
TTH,
version 3.85.
On 2 Dec 2011, 12:38.