Generating garbage…

At JCrete the last couple of years I’ve had the pleasure to be socializing with, among others, HFT people like Peter Lawrey and Martin Thompson.

Those HFT dudes really makes me thinking when I’m implementing stuff. Thinking about how much garbage I create.

In High Frequency Trading systems you cannot afford garbage collection and therefore they are doing lots of tricks to get around generating garbage.

With the stuff I’m doing a gc pause is generally not critical, so generating garbage is no big deal. Writing easy to read- and maintain code is more important.

But then again, it does not harm to think about garbage.
Continue reading

Posted in Fun, Java | Tagged , | Leave a comment


I’m currently designing a user-authentication OAuth2 based service.

I’m trying very hard never ever to reveal anything about users or passwords. Credential-lookup by userid is always done twice. If the user is not found a known dummy-user is looked up instead. If the user is found, a “by guarantee not existing” user is looked up. Just to try to make the timings of existing and not-existing users the same.

Internally a lot of hashing takes place with random and known stuff. Valid and invalid users and passwords all take exactly the same “route”.

At the end, byte arrays are compared, and if they contain the same binary information, the user is authenticated.

In order to ensure this check timing-wise is independent of the outcome, a special equals(byte[], byte[]) method is implemented. Also, a rather special counterpart, the neverEquals(byte[], byte[]) is implemented. This does the exact same comparisons as the equals method, just the outcome is always false, to be used when the user is invalid. Continue reading

Posted in Java, Open Source | Tagged , | Leave a comment


Yeah, I know, this isn’t rocket science. But it is rather nice 🙂

So, I’m working on this JEE project, backed by an Oracle database. Some of my work involves refactoring CMP 2.1 entities into JPA entities.

Here I’m faced with the issue, that sometimes true/false columns are modeled using CHAR(1) as ‘Y’ vs ‘N’. And at other times they are modeled using INTEGER as 1 vs 0. Sometimes both versions are using in the same table.

The natural datatypes in JPA are String and int. So I’m having code doing “Y”.equals(colum) and column == 1 etc. For the String I’ve generally been using an enum called YN having 2 constants, Y and N. So I can do column == YN.Y. Still a bit annoying though…

Just today I realized I could fix both issues with a simple version of my YN enum below. This works both for the CHAR ‘Y’ / ‘N’ case and the INTEGER 1 / 0 case.

And it’s damn simple containing 2 simple convenience methods that does make life simpler:

 * Being used in JPA entities as @Enumerated(EnumType.STRING) or @Enumerated(EnumType.ORDINAL) (N=0, Y=1)
public enum YN {
    N, Y;
    public final boolean bool() {
        return this == Y;
    public static final YN bool(boolean b) {
        return b ? Y : N;

Now I can do column.bool() and I can do YN.bool(something) the other way. And the mapping in the JPA entity takes care of the rest.

Nice and simple, definitely not rocket science.

Posted in Databases, Java | Tagged , , , , , , | Leave a comment

Unit testing really simple implementations

As an independent subcontractor (freelance consultant) I get to work in various very different organisations, with very different approaches towards testing in general and unit-testing in particular.

Some places unit-testing is mandatory and there might even be a code-coverage tool where you must strive to meet a specific threshold.

At other places unit-tests are more like integration tests, where the unit-testing is considered implicit in the integration-unit-tests.

And then there are places where unit-tests are of your own choice, as long as you do not spend too much (measurable) time on them.

In the latter cases you as an experienced developer might feel that unit-testing very simple stuff is superfluous.

Not so! In my experience, it is when you do these simple no-brainer implementations that you make mistakes, simply because you do not have to think. Also, unit-testing simple utility stuff demonstrates corner-cases that might suddenly be used or mis-used in the code where changing even the simplest implementation might break important business logic

In this post I will go through a few very simple utility methods that I’ve worked on recently and talk about some of the finer details – and why unit-testing even the simplest is really important.

Continue reading

Posted in Java | Tagged , | Leave a comment

Bad sample code…

Okay, I just HATE bad code.

I’m not religious about how you express your business logic in the code. I don’t mind “different” indentation or long methods although I try to keep my own code as short and simple as possible. I prefer lots of small classes over a few huge, and I prefer a bunch of short methods (“a screenfull”) over a few huge ones. Complex IF-clauses formed as simple methods etc.

Whenever I’m maintaining code developed by others, I accept the previous developers different habits. I might rewrite (also known as refactoring) parts, especially if there are unit-tests. But only if I think it would benefit the quality and maintainability of the code.

But, when reading books or articles I get really REALLY annoyed when I encounter bad code and bad habits in samples etc. Whenever I come across these things, where the quality is as if the developer is not really a JAVA developer, absentminded or just plain drunk, I loose interest in the rest of the content. As if, if the code is really bad (and untrustworthy) how can I then trust the rest of the content?

Continue reading

Posted in Fun, Java | 1 Comment

Handing over JAVA components to L3 support…

Java Specialist13:13


Udby, Jesper13:13


Java Specialist13:13

we are unable to build with existing set up

can you give us ear file to me

Udby, Jesper13:14

no, unfortunately not, I’m working from home today and do not have access to my dev env

Java Specialist13:14

i will put in weblogic server

Udby, Jesper13:14

I suggest you configure you’r maven setup to use the proper repo so you can build it. It has to be done anyways…

Java Specialist13:15

can you share your maven to me



Udby, Jesper13:15

no… its on m dev env too…

the settings.xml linked from the document i sent you contains information about the repo – you should be able to use that?

which weblogic server btw?

Java Specialist13:18

weblogic server 11gR1

Udby, Jesper13:18

you have a local setup?

Java Specialist13:18


Udby, Jesper13:18


you got a local db setup too?

Java Specialist13:19


Udby, Jesper13:20

yes, datasource. does it point to a local db or one of our dev environments?

Java Specialist13:20


Udby, Jesper13:21

do you have a local db?

Java Specialist13:21


Udby, Jesper13:21


how’s the schema setup?

Java Specialist13:21


Udby, Jesper13:21


Java Specialist13:21


Udby, Jesper13:22

ok, i rephrase: how are the users/schemas, tables, sequences etc setup?


Java Specialist13:22

i will give schema name

usern and password


Udby, Jesper13:23

i don’t know if you are aware of it, but “we” are using what is called “database migration” scripts to do the DDL

Java Specialist13:24

1 min

Udby, Jesper13:24

1 min what?

Java Specialist13:25


database migration is no there with me

Udby, Jesper13:27

well thats not important if you are able to setup the schema/users, tables etc yourself

I was just wondering where you got the details from

Java Specialist13:28

webservice setup document

Udby, Jesper13:29


Java Specialist13:31

Do you have this type of document with you_

Udby, Jesper13:32

nope, not here, might have it in the office…

Java Specialist13:32


is there anu body who will share information_

Udby, Jesper13:33

what information?

Java Specialist13:34

regadring configuartion of java compenent with oSB

Udby, Jesper13:34

what component and what kind of configuration?

Java Specialist13:36

two ear file ie two java componet and after that i will confuge jMS queue with SFDC 

and OSB

Udby, Jesper13:36

first, there are more than two components, you need to tell me which components you need information about

then I can tell you which datasouces and jms queues are necessary

but you can see that in the code, if you like?

take the xxx-feed-parser (from memory, you can see the proper name in the poms/mail/source etc)

Java Specialist13:38


Udby, Jesper13:38

it needs a jms queue, can’t remember the jndi name, but it’s in the annotation in the MDB

and it needs a datasource, can’t remember the jndi name, but its in the persistence.xml file

Java Specialist13:39

i have JMSQUEue is there with me

Udby, Jesper13:39


Java Specialist13:40

while i am doing yYYY project

Udby, Jesper13:40

ok, good, but its probably not the same queue:)

Java Specialist13:41


Udby, Jesper13:41

you can see the jndi name of the jms queue in the annotation in the mdb – message driven bean

Java Specialist13:44



i am opening weblogic server

Java Specialist13:53


Udby, Jesper13:54


Java Specialist13:55

i am able to jndi nameof the JMS queue

for YYYY

Udby, Jesper13:55


I wasn’t referring to the jndi name of the jms queue in yyyy

you do know what an annotation is, right?

Java Specialist14:00


Udby, Jesper14:00

ok, you are in trouble

do you know what a message driven bean is?

Java Specialist14:01


Udby, Jesper14:03


in the mdb (aka message driven bean) there is an annotation that tells it which jms queue it should connect to

i can’t remember the proper name of it, but somewhere in the xxx-feed-ejb (i think it is) there is the java source of a message driven bean – I even think it is called something like Xxx…Mdb or similar. In that source you can find the annotation containing the name of the jms queue

also, in that project, there is a persistence.xml – you do know what that is?

Java Specialist14:06

jesper please share me the ear file to deploy javacomponents in weblogic server

Udby, Jesper14:06

sorry, i cant

you should configure your maven to use the proper repo, then you can build it yourself

btw: there is more than one ear

one component = one ear


Posted in Fun, Java | Leave a comment

Salesforce wsc (sfdc-wsc): new release 23 coming

The current situation is a mess. There are now 3 known versions of the sfdc-wsc tool:

I will try to merge relevant changes from the codebase at mvnrepository but please notice it has already forked. The code style at mvnrepository is slightly different to my style and I take the liberty to refactor stuff in order to keep classes clean and without too much responsibility (e.g. ConnectorConfig should not have the responsibility of creating connections, adding stream wrappers and what not).

Released – wsc-23.jar – with the following:
Continue reading

Posted in Java, Salesforce | Tagged , , , | Leave a comment

Salesforce wsc hacking: yet another Open Source encounter?

As I wrote in an earlier post I’ve volunteered to become a committer to the wsc tool and are in the progress of making minor tweaks and enhancements for a coming release 23.

My plan was that this release should be no more than a “maintenance” release covering most of the relevant issues. And I do have a number of ideas for major changes for a possible release 24, e.g.:

  • Fixing issue 51 – or at least provide a usable implementation hopefully inspired by input from Martin Haynes
  • Reworking/reimplementing the wsdlc tool and templating mechanism
  • Reworking infrastructure parts, possibly using JAXB/JAX-WS
  • Mavenize the build, divide build tools and infrastructure, 2 perhaps 3 artifacts
  • Adding unit tests

I stopped further developments on the “23 branch” when I realized that there apparently already was a “fork” on github.
Continue reading

Posted in Java, Open Source, Salesforce | Tagged , | Leave a comment

Salesforce wsc hacking: new committer

Ok, things change rapidly sometimes.

The short story is that I wrote directly to the Owners of the WSC tool in order to get some information about when changes could be expected.

The response was basically that they no longer maintain the WSC tool and if I was interested I could become a committer. I was and now I am 🙂

Currently working on wsc-23 to be released soon – probably by the end of January 2013.

Contains most of the stuff already discussed here and probably some other enhancements regarding the wsdlc tool.

Update 2013-01-31: There appear to be some confusion about the proper version/codebase of the wsc tool. I will not make a new formal release until I get some definitive answers… We might need to fork 🙂

Posted in Personal, Salesforce | Tagged , , | Leave a comment

Salesforce wsc hacking: getting rid of SessionTimedOutException

The SoapConnection java class sports a private static inner Exception, the SessionTimedOutException. This Exception is used internally only to quickly pass control from the parseDetail() method back to the send() method.

This is bad practice, using an Exception to control flow of execution. And in this case the infrastructure is doing exception handling in the first place… There has to be a better way.

Continue reading

Posted in Java, Salesforce | Tagged , , , | Leave a comment