27.

Checklist for the Patterns

For the following list of problems—covered in our patterns section—that can occur whether you are designing, debugging, implementing, or maintaining software, a potential answer can be found in the indicated chapters, shown in Table 21-2.

Table 21-2: Pattern Checklist

PROBLEM

SEE

The code acts as if a previously corrected bug is still there.

Rogue Tile Chapter 7

Errors are popping up in a job with lots of cut-and-paste code.

Rogue Tile Chapter 7

A change in the type of a value field in a class is causing an error.

Rogue Tile Chapter 7

A modified method compiles but returns a reasonable, but wrong, value.

Rogue Tile Chapter 7

I've built a separate TreeVisitor interface with separate accept() methods for each return type I want to use.

Rogue Tile Chapter 7

At runtime, I get a ClassCastException even though I use the same TreeVisitor interface for all occasions and insert casts as appropriate with each Visitor method invocation.

Rogue Tile Chapter 7

I got a damned NullPointerException and I can't figure out what it's telling me!

Null Pointers Chapter 8

Dangling Composite Chapter

9 Null Flag Chapter 10

Run-On Initializer Chapter 9

I got a NullPointerException; how do I find where the variable is assigned to null?

Null Pointers Chapter 8

Is there a rule or tool to help statically determine which programs will throw NullPointerExceptions?

Null Pointers Chapter 8

I'm getting a NullPointerException in code that uses recursively defined datatypes.

Dangling Composite Chapter 9

Is there a problem in defining a recursive datatype so that some base cases of the definition are not given their own classes?

Dangling Composite Chapter 9

Is there a problem with inserting null pointers into the various composite datatypes?

Dangling Composite Chapter 9

My code throws a ClassCastException when I do a recursive descent over the data.

Double Descent Chapter 11

Help! When I recursively descend my data, more than one step down is taken in a single recursive call.

Double Descent Chapter 11

Is there a problem with creating multiple identical instances of the same class?

Double Descent Chapter 11

I'm using instanceof and equals to check for class and object identity; is there a better method?

Double Descent Chapter 11

What can I do to weed out "0" values in consecutive nodes?

Double Descent Chapter 11

I can't get my code to dispatch properly after a method call.

Double Descent Chapter 11

Would eliminating the Leaf class and representing Leaf nodes with null values in the left and right fields of a Branch fix the ClassCastException and keep me from having to cast?

Null Pointers Chapter 11

I don't really see why I need to comment all the invariants in my code.

Double Descent Chapter 11

I've got it! To avoid a ClassCastException, I'll wrap each cast in an instanceof check. Right?

Double Descent Chapter 11

What are the disadvantages of using an instanceof check to avoid a ClassCastException?

Double Descent Chapter 11

Are there any "gotchas" when it comes to the design of GUIs?

Liar View Chapter 12

My GUI passed all my tests, but now my customer is calling me with problems. What's up?

Liar View Chapter 12

I know about writing unit tests as a way to debug, but do I really need so many?

Liar View Chapter 12

My tests and the runtime behavior of my code don't match. Why?

Liar View Chapter 12

My tests and the runtime behavior give inconsistent results. Could the tests be wrong?

Liar View Chapter 12

How do GUI tests work?

Liar View Chapter 12

Can the Model-View-Controller (MVQ architecture be at fault in my code?

Liar View Chapter 12

Is there a best time to check the model through the view?

Liar View Chapter 12

If I can't easily automate GUI tests, how can I use tests to check my code?

Liar View Chapter 12

Should I refactor all the time?

Liar View Chapter 12

Are there other components necessary to \effective, perpetual refactoring of code?

Liar View Chapter 12

I've heard the Java Robot class is good for GUI testing. Is it useful in every instance?

Liar View Chapter 12

Can non-GUI data-displaying software also show discrepancies in testing and runtime results?

Liar View Chapter 12

My data-input code works fine for a while, then crashes, even though it's working on the same task. What's wrong?

Saboteur Data Chapter 13

The data that causes a crash comes from a large data structure over a network (instead of in memory or from a database). Is that the problem?

Saboteur Data Chapter 13

Which is the probable cause of the data corruption—syntax or semantics?

Saboteur Data Chapter 13

Which is the probable cause of the data corruption—manual editing or automatic file generation?

Saboteur Data Chapter 13

Checking for corrupt input data by parsing seems like a lot of work! Isn't that what compilers are for?

Saboteur Data Chapter 13

Would type checking help identify semantically corrupt data?

Saboteur Data Chapter 13

What if I can't check the data on input, as I can with existing data?

Saboteur Data Chapter 13

Would iteration of the data be a good tool for weeding out corruption? Under what circumstances?

Saboteur Data Chapter 13

Should I iterate over data, accessing each bit of data as it would be accessed in the deployed application?

Saboteur Data Chapter 13

Is it always possible to discover corrupt data before it causes a problem? If not, why?

Saboteur Data Chapter 13

Hey, can splitting a text line into two Strings cause hard-to-detect, corrupt data?

Saboteur Data Chapter 13

OK. I overloaded one method, then another one (that I didn't touch) broke. What gives?

Broken Dispatch Chapter 14

Is it possible that my method arguments don't match?

Broken Dispatch Chapter 14

Can adding new methods cause others to break?

Broken Dispatch Chapter 14

If a constructor with a general method is overloaded with a more specific method, what happens?

Broken Dispatch Chapter 14

Should I "infest" my code with tests?

Broken Dispatch Chapter 14

My code is treating different types of data as the same type. What's up?

Impostor Type Chapter 15

My code won't recognize some of my data types.

Impostor Type Chapter 15

Are there any problems in using tags in special fields to distinguish data types?

Impostor Type Chapter 15

Why should I use the static type system to distinguish data types?

Impostor Type Chapter 15

I've got a solution to avoid type mismatches: I'll use an if -then-else block to dispatch on the appropriate type. Will that work?

Impostor Type Chapter 15

My code leaks memory. What could be the cause?

Split Cleaner Chapter 16

Why is my program freeing up resources, such as my database connection, too early?

Split Cleaner Chapter 16

To free resources, should I get and free the resource in the same method?

Split Cleaner Chapter 16

To ensure that my resource is freed, should I trace through each possible execution path of the code?

Split Cleaner Chapter 16

Some execution paths of my code aren't freeing the resource exactly one time. Why?

Split Cleaner Chapter 16

Should I try to anticipate and code for all the ways in which a program will be extended?

Split Cleaner Chapter 16

I discovered an execution path that doesn't include the appropriate clean up code, so I'm adding it to that path. That'll work, right?

Split Cleaner Chapter 16

How can I go about formally specifying an interface?

Fictitious Implementation Chapter 17

Why, when I make a certain implementation of an interface, does one client class that's supposed to work with the interface break?

Fictitious Implementation Chapter 17

Is it OK not to explicitly document invariants in an interface?

Fictitious Implementation Chapter 17

What are the drawbacks of loading my code with extra invariants?

Fictitious Implementation Chapter 17

As a safeguard, can I specify invariants that can all be checked statically?

Fictitious Implementation Chapter 17

Is it OK to restrict the specification of interface invariants to type signatures?

Fictitious Implementation Chapter 17

What is an assertion? Are there different types assertions?

Fictitious Implementation of Chapter 17

Where should assertions be included in an interface implementation?

Fictitious Implementation Chapter 17

Does the inclusion of assertions add heavily to execution overhead?

Fictitious Implementation Chapter 17

Would assertions alone be enough to capture all of the rules I want to specify on an interface?

Fictitious Implementation Chapter 17

Can I use unit tests to provide limited specification of extra invariants for an interface?

Fictitious Implementation Chapter 17

Can my set of unit tests check an interface implementation over all possible inputs?

Fictitious Implementation Chapter 17

Which are more expressive, type signatures or unit tests?

Fictitious Implementation Chapter 17

My multithreaded code locks up and prints stack traces to standard error. Why?

Orphaned Thread Chapter 18

What about if I just use single-threaded design from now on?

Orphaned Thread Chapter 18

My program just freezes, which is confusing. Are there other ways I can notify the user that there is a problem?

Orphaned Thread Chapter 18

Hey! Did the stop() method on threads change?

Orphaned Thread Chapter 18

In what type of programming am I more likely to encounter an abandoned second thread?

Orphaned Thread Chapter 18

I've got a NullPointerException where an uninitialized field is accessed. What's up?

Run-On Initializer Chapter 19

I don't think all the fields of my class are initializing. Did I not build the constructor correctly?

Run-On Initializer Chapter 19

Is there something wrong with constructors that require client classes to initialize instances in several steps?

Run-On Initializer Chapter 19

This class has had fields added several times. Is it possible that it is not initializing properly because of the additions?

Run-On Initializer Chapter 19

Does it matter what order I execute statements in?

Run-On Initializer Chapter 19

Should I convince my customer to throw out old code and start fresh?

Run-On Initializer Chapter 19

I'm working with legacy code. Is it OK to modify the constructor signatures?

Run-On Initializer Chapter 19

What's the best way to control NullPointerException errors when working with legacy code?

Run-On Initializer Chapter 19

What about using an isInitialized() method in the class?

Run-On Initializer Chapter 19

How can I ensure that instances of my class will be in a well-defined state at all times?

Run-On Initializer Chapter 19

If I filled in class fields with null values, wouldn't that help with initializing?

Run-On Initializer Chapter 19

What's a quick way to determine whether an instance has been initialized?

Run-On Initializer Chapter 19

What should I do to avoid initialization problems with new contexts?

Run-On Initializer Chapter 19

What is the best way to represent default values?

Run-On Initializer Chapter 19

Will using special classes to represent default values cause a performance hit? If so, why?

Run-On Initializer Chapter 19

Is there a way to check for initialization without casting at runtime and taking the associated performance hit?

Run-On Initializer Chapter 19

Someone told me that including methods that always throw exceptions is sometimes justified, but that seems stupid. What do you think?

Run-On Initializer Chapter 19

Why does my code work on some Java Virtual Machines but not on others?

Platform-Dependent Bugs Chapter 20

Why does my code work on some versions of a JVM and but on others?

Platform-Dependent Bugs Chapter 20

Why does my code work on some operating systems and not on others?

Platform-Dependent Bugs Chapter 20

What's the difference between a specification-related bug and an implementation-related bug?

Bugs/Specs/Implement Chapter 20

Is there a roundup of the bugs caused by specifications and implementations of Java?

Platform-Dependent Bugs Chapter 20



Bug Patterns in Java
Bug Patterns In Java
ISBN: 1590590619
EAN: 2147483647
Year: N/A
Pages: 95
Authors: Eric Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net