Accessed Nulls

by in CodeSOD on

"The attached class connects to an Access database," writes Nicolai. That's always a good start for a WTF. Let's take a look.

public class ResultLoader {

	private static Logger sysLog = Logger.getLogger(ResultLoader.class);
	private static String url = "somePath";

	/**
	 * get the ResultTable from the Access database
	 * 
	 * @param tableName
	 * @return
	 */
	private static Table getResultTable(String tableName) {
		try {
			// create a new file with the path to the table
			File db = new File(url);
			// let Jackcess open the file and return a table
			return Database.open(db).getTable(tableName);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * load result from DB
	 */
	public static void loadResult() {
		String tableName = "Result";
		Table resultTable = getResultTable(tableName);

		if (!resultTable.equals(null)) {
			Map<Integer, Float> yearConsumption = new HashMap<Integer, Float>();

			for (Map<String, Object> row : resultTable) {
				/*
				 *  [snip] does something with the table's rows
				 */
			}
			Result result = new Result(00, new Date(), consumptions);
		} else {
			sysLog.info("There is no data object in the Access Database!");
		}
	}
}

Left Hand Right

by in Error'd on

Tim Y. is on Fire with this burn. "Competing teams inside Google? Or just the AI recognizing marketing tactics?"


Reflect on Your Mistakes

by in CodeSOD on

While Java didn't invent putting a toString method in the base class of every object, it certainly made it mainstream. The nice thing about the method is that it allows you to turn any object into a string, though it's up to the implementor to decide what a good string representation is. But what if you want to ensure that the object you're handed is really and truly a string, not just something you can convert to a string?

teknopaul's co-worker found their own solution:


Minimal Commentary

by in Coded Smorgasbord on

Comments explain a lot about our code. And sometimes, the comments explain more than the code itself.

Alastair found this lovely comment, which demonstrates an excellent, if confusing, understanding of a boolean "or":


Suspicious Contents

by in CodeSOD on

While poring through some VB .Net code, John noticed some odd things in their datamodel. For example, a different process would scan files, and log any "suspicious" files into a database. The program John supported would then report on that data.

One of their classes had a property which looked like this:


Spaced Out Replacement

by in CodeSOD on

You have some text, and need to replace every sequence of spaces with a single space. E.g., My text becomes My text. Now, if you're most of us, you ignore the famous quote and reach straight for regexes.

But Samuel's co-worker isn't most of us.


Testing 1,2,3,4,5

by in Error'd on

An anonymous friend sent us our frist test in prod for this week. And then there will be more, and more, and more. "This came up in Kaspersky's Blog's RSS. If you're lucky they might still have the error up in the original URL." I don't know if "chron" is just how "cron" translates to Russian and back, but the test appears to have succeeded.

timely post


Totally Valid

by in CodeSOD on

Greg's co-worker really wanted to make sure that a variable was correctly set to true or false. So they did this:

if (isValid == true)
{
	isValid = true;
}
else
{
	isValid = false;
}

Archives