Pencils Down

This weblog is about my experiences in software development

Browsing Posts tagged Java

I ran across this ‘error’ this week. After poking around the internet for awhile it looked like this is due to a bug in an older version of the SAX parser in the xerces library.

Well, we have quite a bit of code in production, so can’t just update the jar.

My original code was simply using the class loader to read in an xsd and use the Source of the xsd for a Schema that would be used to validate some xml entered by the user.

I toyed with this some and thought the exception sounded like it thought there was extra cruff after the closing tag of the xsd. So, I read in the xsd to a byte array, as before. I kept track of the byte count of read bytes, looped over the byte array (for that count), added each byte to a StringBuffer then converted the StringBuffer to a String. Voila!

Was getting this error trying to run a hibernate query in a thread during startup.

Need to add @Transactional to the flowers in mississauga and the class. This tells hibernate to add the flowers in mississauga and the session to the florists mississauga and the thread.

We have a case where people can submit multiple changes to their database records. Each change is handled separately with code like:
– from table where attribute=value
– object.setChangedValue(updatedValue)
– hibernate.flush()

However, if the user happened to submit two changes to the same record the initial query will return the initially obtained object – NOT the updated value.

We fixed this by performing a refresh() once we get the object back from the hql query.

is a program which uses static analysis to look for bugs in Java code.

It is offered as an Eclipse plugin. So, just like any other plugin:

  • right click on the item(s) you want to check,
  • click on “FindBugs” and
  • off you go.

Some of the issues that have come up for me:

  • use of static SimpleDateFormat – it’s not thread safe – who knew?
  • new coding did not have a setter for a dao – hopefully testing would have shown the error
  • compares on different object types – the code looked correct, but oh oh…

I love things that just work

Just saw thatJava 8 fixes the date problem –

I have run across an issue several times with Maven in Eclipse. If a dependent project is updated my project is toast for the rest of the day. I have tried shutting down Eclipse, rebuilding all, updating all dependencies: you name it.

After being fed up with this today I tried shutting down my machine and starting anew. Guess what? The build worked! No changes whatsoever to any of my code.

Just got this (while trying to create history records of a set)

The error occurs because an attempt was made to store the exact same Collection object more than once (possibly in multiple objects).

In my case I just attempted to copy the collection out of the real object into the history object.

I think this is enforcement of the not allowing multiple inheritance in Java. Also, not sure how this would work at the database level

Another developer and I started seeing this running an app locally.

While it sounds really interesting with hints of transaction state it was really just noise cascading up from a missing property in the local properties file.

Yes, it did not occur on server. But again, from the wording it sounds like some filter error or the like and we use different authorizations running locally.


No comments

VerbalExpressions is a library available on for Java,C++,PHP…

It allows you to build an expression using a VerbalExpressions object.  The example from this site is below (showing Java but very similar in other languages).

VerbalExpression testRegex = new VerbalExpression ()
                                 .anythingBut(" ")

// Create an example URL
String url = "";

// Use VerbalExpression's testExact() method to test if the entire string matches
// the regex
testRegex.testExact(url); //True

testRegex.toString(); // Ouputs the regex used:
                      // ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$

VerbalExpression testRegex = new VerbalExpression ()

String testString = "defzzz";

//Use VerbalExpression's test() method to test if parts if the string match the regex
testRegex.test(testString); //true
testRegex.testExact(testString); //false

Turn off this setting: Project->Properties->Java Compiler->Enable Project Specific Settings

Likely there is something in your specific settings that is off (again likely wrong JDK)