FreeCAD Tutorial Office Chair Part 2: Wheels

23. July, 2019

Here is part 1: FreeCAD Tutorial Office Chair Part 1: Setup and Constraints


What’s an office chair without wheels? A wreck. So let’s give them some:

And done. In our next part, we’ll see how we can create the whole foot (two wheels with an axis and a rotating joint to attach to the base) … What?

All right.

As with the rectangle from part 1, we need an outline for the wheel. But before we can start, what should we do with the rectangle itself? We could delete it or create a new project or rename it. I suggest to rename it so you have something handy where you can play around.

Select the node “Body” and press F2 or right click and select “Rename”. Just start typing the new name. That solves half of the problem.

Sketching an Outline

With that out of the way, we need a new body for the wheel. Make sure you’re in the “Part Design” workbench

"Part Design" workbench selector

“Part Design” workbench selector

and click “Create new body”. You might get an error:

That happens when you create a new body while another is currently “active”. Most operations work on the active body. That way, you don’t have to select the target of your operations all the time. Just click OK to get a new, active “Body001”.

Rename it to “Half Wheel”. Why half? It’s good practice to be lazy. Since most chairs have symmetrical wheels (one on each side of the joint), we’ll just draw one of them and then ask the software to create a mirror copy:

Neat, right?

With the body “active” (= the name is bold), create a sketch. If the “Half Wheel” isn’t active, double click on it.

Again, we chose the XY plane:

Hm. I don’t know about you, but I don’t want to see the rectangle while I’m working elsewhere. If we could just hide it … yes, we can.

Go back to the “Model” tab, right click on the rectangle node and select “Toggle visibility” (shortcut: Space):

Much better! Pick the polyline tool and create a rough outline:

The bottom will become a hole for the axis of the wheel, the top is the surface on which the wheel is rolling. As you can see, FreeCAD already created a ton of constraints: Horizontal, vertical and “fix point on object” ones. In my case, it’s already complaining:

I clicked on the link in the solver message “(click to select)” and the offending constraints are green. It’s a vertical constraint in the top left and a horizontal constraint in the bottom right.

I could delete them but I feel those constraints are correct. Instead, the “fix point on object” constraints might be wrong because my outline has no freedoms left in it. If I pick the right side, I can’t move it because the bottom point is nailed to the X axis. Since the dimensions are most certainly wrong, this is bad. Also, the wheel will be stuck in something. Imagine an axis going through the origin. This axis will be in some kind of holder. If the wheel touches the Y axis, it will probably touch whatever holds the axis. We don’t want that kind of grinding, so we have to move the four points on the Y axis away and the “point on object” constraints prevent this.

Let’s delete all of these constraints:

Using Dimensions

Ah … freedom. Ahem. Let’s start with some simple constraints to get the sizes roughly right. The rolling surface will take all of the weight, so let’s give it 3 mm. The same is true for the material holding the axis. The “side” of the wheel will just take pressure along the material (no torsion), so it can be 2 mm. To save material on the (metal) axis, let’s not extend it all the way out to the side of the wheel. Let’s make the wheel 10 mm thick and 50 mm tall. With these dimensions, we can make the hole for the axis 6.5 mm deep. Deep enough for a good hold:

Note that the height is half of 50 mm = 25 mm.

But it doesn’t look great. Click on the dimensions (the numbers) and drag them until you can read everything properly:

Much better. The 2 mm at the top isn’t great but good enough for now. Let’s move the wheel outline to the correct position. The two bottom dots should be anywhere on the X axis. To achive this, select one of them and the origin and constrain the vertical distance to 0 mm:

Above, we said that we want the wheel to be away from the holder of the axis. Select one of the two vertical points near the bottom left and constrain the horizontal distance to the origin to 1 mm:

sigh Wrong way again. To fix:

  1. Delete the constraint
  2. Move the vertical line to the other side of the Y axis
  3. Apply the constraint again

While dragging the line, you’ll notice two things:

  1. The whole “box” at the bottom moves along
  2. The side and rolling surface stay in place

FreeCAD tries to do what you want with the least amount of change.

Using Formulas

Let’s finish the hole for the axis. For this, we need to assign a height. For a 3 mm axis, this would be 1.5 mm. Which we could calculate in our head but how about an axis which is 7.125 mm? To spare use the humiliation, let’s use the little “f(x)” button in the text box. The formula would be “3/2”:


To denote the fact that this is a calculated value, the constraint has an orange color. This leaves me with a single degree of freedom left. If you look closely, you’ll see that the bottom and top parts have different widths. If you click on the outline and drag it, you can see that the freedom is only in the length of the horizontal lines at the bottom. There are different ways to fix this:

  1. We could give the the bottom a total width of 10 mm
  2. We could constrain the length of the white line on the X axis
  3. We could constrain the length of the second of the four horizontal white lines (from the bottom)
  4. We could constrain the horizontal distance between the two leftmost vertical lines

I’ll go for the last approach because that allows us to easily modify the width of the wheel and the gap between wheel and axis holder and, later, the top cover of the wheel:

I used a 0.5 mm horizontal constraint.

FreeCAD is happy with the result and so am I. Close the outline to go back to the “Part Designer”


To turn the outline into a wheel, use the tool “Revolve a selected sketch”. The sketch should be selected; if not, make sure it is:

Now that doesn’t look right:

By default, FreeCAD rotates around the vertical sketch axis (see the “Axis” combobox). Change that to “Horizontal sketch axis” and you have a wheel:

Make sure the rotation angle is 360 (= full circle) and “Symmetric to plane” and “Reversed” are both off.

After clicking OK, our tree looks like this (I’ve opened the “Revolution” node):

As you can see, FreeCAD remembers our operations: We started with the sketch (outline), then rotated it.


As wheels go, this one is nice but the edges are too sharp. They would feel bad to the touch and would easily break (they would also be very hard to produce). Let’s round them. Select the rim and click the fillet tool:

That looks much nicer:

Since we want the same fillet on the outside, click “Add ref”, select the other rim to get:

Now for another fillet on the inside (1) with a radius of 3 mm (2):

Too much? Double click “Fillet001” and change the radius to 2 mm:

Now, I want the same on the axis hole. Double click the fillet again and add the additional edge:

All right. This looks like a nice wheel which won’t break easily:

Note that I’ve renamed most nodes to make it easier to tweak the design later.

Project file: Office Chair Tutorial Part 02

Next part: FreeCAD Tutorial Office Chair Part 3: Mirrors and Holes

FreeCAD Tutorial Office Chair Part 1: Setup and Constraints

22. July, 2019

After starting FreeCAD 0.18, you’re greeted with this windows:

FreeCAD main window

FreeCAD main window

At the top are the toolbars, on the left side are the current model tree and in the center is the main work area.

The main work area contains a tab “Documents” where you can start a new project and see your recent ones and a tab “Help” which gives you access to the online help. If you have two monitors, I suggest to open a web browser on the second screen and open this URL:

Please read the part about “Navigating in the 3D Space” so you know how to move (pan) the drawing board and how to rotate it and, more importantly, how to reset it to a sane state 🙂

New Project

Let’s start with a new project. Click “Create new…” in the “Documents” tab.

This creates an unnamed project. To give it a name, save the file using “File” / “Save…”.

Working with Constraints

FreeCAD has several main concepts. Let’s look at two of them: Sketch and Part. A sketch is the outline of something. After designing it, you can use a 3D operation like “pad” (often called “extrude” in other software) or “revolve” to create a 3D body from the outline. Other operations cut holes into parts or arrange then in patterns.

The result of all those operations on parts is called “body”.

In order to create our wheel, we need a body, first. To create one, select the “Part Design” workbench:

"Part Design" workbench selector

“Part Design” workbench selector

This will give you a new toolbar:

Create body icon

Create body icon

The first icon is the one we want. It will add a node “Body” to the tree with a child “Origin”. This child is the coordinate system of the body. Each body has their own (since they are independent of each other).

Tree with the first body

Tree with the first body

Tip: Try to design your bodies in such a way that the “handle” (= the must useful point to place the body) is at the origin (0,0,0).

Now that we have a body, we can create our first outline using the second icon. FreeCAD will switch from “Model” to “Tasks” and ask for the plane in which you want to draw:

Select plane in which to draw sketch

Select plane in which to draw sketch

FreeCAD is a 3D CAD software but editing 3D with a 2D mouse is tedious and error prone. To work around this problem, the designers of the software came up with a trick: They let you draw the outline of a shape and then give you tools to turn the outline into a volume.

For our wheel, we’ll draw the outline and then rotate it around the wheel’s axis to get a complete wheel.

You will now have to decide in which plane you want to draw the outline. If X is “left-right” and Y is “up-down”, then Z is “closer-farther”. This gives you three planes: XY (what we all used in school), XZ (horizontal or ground plane) and YZ (vertical but perpendicular to XY).

For example, you could think that the wheel stands on the ground, it’s axis parallel to the X axis, and you’re looking down on it. If you think like this, the most natural approach is to cut the wheel horizontally and remove the top part. Now you can see the outline of the wheel in the in the XZ plane.

Or you can think of the wheel as standing in front of you. Now, we cut it vertically along the XY plane to get an outline.

Or you can think of looking at the wheel from the side. In this case, the outline would be in the YZ plane.

Let’s start with XY (XY_Plane) just like in school. After clicking OK, you’ll see the “Sketcher” workbench:

Sketcher Workbench

Sketcher Workbench

All this workbench switching probably feels a bit scary. The advantage is that you won’t see thousands of icons.

Tip: You’ll be working a lot with constraints. To make your life easier, pull down the constraint toolbar down like I did to be able to see all icons at once.

To the left are now three panels under “Tasks”: Solver messages, Constraints, Elements.

Elements is a list of basic shapes that make up the outline. That can be lines, arc, circles, polylines, etc.

Constraints lists the properties which must be fulfilled to create a “correct” outline. For example, if you have two lines which must be parallel, the output is wrong when the lines are skewed.

FreeCAD uses a “solver” to determine the correct outline. The topmost panel is used to keep you informed about the success or failure of this process.

Confused? Let’s start with a simple example and create a rectangle from four lines. Click the “Create a line” tool (shortcut: L). Now click for the first point, move the mouse, click again for the second point. Repeat 3 times to get four lines like so:

Wannabe Rectangle

Note the little red line next to your cursor. This tells you that the tool is still active. To deactivate it, click the right mouse button once.

But that’s not a rectangle, you say. Why not?

Well, first of all, the corners should be closed. To fix this, I use the “Coincident Constraint” (shortcut: C). Select two points that should have the same position. There are two ways to do this:

  1. Click and drag a rectangle around two points
  2. Click on two points.

To clear the selection, click on the blue background of the drawing.

Afterwards, you should have two green points and 7 red ones (6 line ends and one origin):

Click on “Coincident Constraint”:

Two things happen:

  1. The second point will move to the first one
  2. A new item “Constraint1” will be added to the list of constraints

Click on the new corner and drag the mouse around to see that the endpoints of the two lines are in fact “connected”.

Repeat with the other three:

Still not a rectangle but closer. What else defines a rectangle?

90° angles in the corner. Let’s add this constraint as well. First, select two lines with a common point by clicking on them to turn them green, and then on the “Constraint Angle” icon (1) to get a new dialog which asks for an angle:

As you can see, the tool offers the current angle as default which is great if you just need a small adjustment. Enter “90” and close the dialog with OK. You’ll see a new “Constraint5” in the list with “(90 °)” behind it but the result looks off:

What happened? Well, FreeCAD just made sure those two lines are now at a 90° angle with respect to each other. It didn’t rotate the whole rectangle. This allows you to create rectangles at all angles. To fix the right side, let’s make it parallel to the left side. Select the two sides and click the “Constraint parallel” (icon with two diagonal parallel lines):

Note “Constraint6” plus the small icons next to the vertical lines.

Also notice that the rectangle rotated. Annoying, isn’t it? But we didn’t tell FreeCAD where the rectangle is supposed to be, so it shifts it around to make our demands work.

One side left. To fix it, we have three options:

  1. We can make it parallel to the bottom edge
  2. We can add a 90° angle in either corner
  3. We can assign a length to the left or right side and then add an “equal length” constraint to the other side.

Since less is more, we’ll just add another parallel. But keep in mind that there is often more than one way to get to a result:

Finally, a rectangle (almost a square). But if you look at the “Solver messages” panel, it says “Under-constrained sketch with 5 degrees of fredom”. What does that mean?

It means that while it’s a rectangle, that’s not good enough for CAD purposes. For example, it has no defined width or height. Imagine buying a car where you don’t know the size in advance!

Let’s create a rectangle with is 7.5 mm tall and 12 mm wide.

Select the left side, then click “Fix a length of a line” (1):

Enter “7.5” and click OK.

You will notice that both the left and right side of the rectangle changed their lengths (and it jumped). This is because of our parallel constraints: FreeCAD will keep the shape for us, even when things change!

Set the width to 12 mm in the same way:

This gets us down to 3 degrees of freedom. In our case, that the X and Y position of the rectangle and the orientation.

It’s good practice to define a “handle” or “attachment” point. In our example, let’s say that the bottom left corner is our attachment point. This point should be at the origin. Select the origin (click on it or use the menu item “Sketch” / “Sketch Tools” / “Select origin”; shortcut: Ctrl+Shift+O), then the bottom left corner of the rectangle and finally “Coincident Constraint”:

To get a feeling how the constraints work, grab a side or corner and drag it around. See how the rectangle keeps it’s shape and only rotates around the bottom left corner?

Almost done. Add an angle constraint of 17.5 ° between the X axis (just click the horizontal line) and the bottom edge:

What happened? Why is it going “down” instead of “up”?

FreeCAD doesn’t count angles from the X axis. It just keeps the angle between the two selected lines by moving everything the least amount. In this case, the downward direction was “closer” and therefore, it used this solution. If you want the other result, delete the constraint (or use undo), rotate the rectangle up and try again:

Note that the whole outline turned green to indicate that it’s properly defined, now.

In the Solver panel, you can see “Fully constrained sketch”.

To finish the outline, scroll up in the “Tasks” panel and click “Close”:

Final result as download: Office Chair Tutorial Part 01

Over time, you’ll find better and faster ways to do things in the software. Let’s try it. Draw a rectangle instead of four lines:

Note that the software already filled 8 constraints for you. Constrain the left bottom edge to the origin:

Constrain width and height as above:

And assign an angle of 17.5 ° to the bottom line:

Hey! What’s wrong?

Well, there is a constraint that the bottom edge is parallel to the X axis (the red dash). It’s either Constraint 5 or 6. The solver tells us “Over-constrained sketch” and, helpfully, “Please remove either constraints 6 or 12”. Also, there is a dialog “Negative datum values are not valid for the constraint with index 11”.

The dialog is confusing and not very helpful. Sorry for that. Just close it.

Huh? Everything is fine?

Oh, it just deleted the angle constraint! That’s not what we want. But it already gave us a clue: The “bottom must be horizontal” constraint is #6 (from the error message above). Delete it and try again with the angle constraint:

Well … almost 🙂 Double click on the angle and change it to “-17.5 °”:

We’re getting there. Delete constraint 5 and make top and bottom parallel:

A parallelogram (or rhomboid)! Do you feel the power of the tool? How it tries to fulfill your expectations? Remove the vertical constraints and drag an upper corner of the rectangle around. You probably thought it would slide sideways but instead the corners “rotate” around their bottom counterparts. If you pick the right bottom corner, you can only slide it along the bottom edge, shortening or extending it in the process. That’s what FreeCAD means when it says “2 degrees of freedom”.

To fix this, you need to apply the rules of rectangle (all four corner angles must be 90 °). Let’s start by using a 90 ° constraint in the bottom right corner:

Close. To get the same result as before, we either need to assign another 90 ° constraint or make the left and right side parallel. Let’s add a angle constraint in the top right corner:

A new error: “Sketch contains redundant constraints” and (another) useless dialog “Datum 90.00 ° for the constraint with index 10 is invalid.” What happened? We have a parallel and two 90 ° constraints. That’s too much; either two 90 ° constraints or one parallel plus one 90 ° constraint would be enough to achieve the same result. In a nutshell, FreeCAD tries to help us avoid unnecessary constraints. For one, they are futile and secondly, they might get in the way later when we want to change something. Clicking OK in the dialog and our angle constraint will be gone. Two to put the 90 ° angle into one of the two left corners:

All right. Same result as above but using a different route. This time, we made more “mistakes” which helped us to understand how constraints can both help and hinder us.

Office Chair Tutorial Part 01 Two Rectangles

In the next part, we’ll use constraints to define the outline of a chair wheel. FreeCAD Tutorial Office Chair Part 2: Wheels

EU Copyright Reform Art 11&13

22. March, 2019

The reform in the current form was designed to increase profits of the big players in the game: the few big music labels, movie companies and news agencies.

Since they want those additional billions, I think it’s moot to argue against the reform. If we stop them this time, they’ll be back next week.

Instead, I suggest to change the reform to force them to provide online services to license their content.

A few clicks and you’re allowed to use a piece of music or video or text for your own work. Yes, it will cost money but videos don’t grow on trees, either.

That way, the poor mega companies on this planet look good in front of their shareholders and the people creating art don’t have to waste money on fending off lawsuits.

Oh, and maybe add a clause in the law that the companies have to pass a real amount of money on to the artist. Right now, they are actively being starved by the companies (except for a few topstars who could afford the lawyers to get their share).

Key Escrow that Might Work

12. December, 2018

Instead of encrypting everything with a single government key, several government agencies need to provide new public keys every day. The private key must be under the control of a court. Each secure encryption channel needs to subscribe to one or more of those agencies. The court must delete those keys after six months.


  • No attacker will be able to monitor any channel of communication for a long period of time.
  • Generating and sharing new keys can be automated easily.
  • A single stolen key will just compromise a small fraction of the whole communication.
  • Judges will decide in court which messages can be deciphered during the storage period.
  • It’s still possible to decipher all messages of a person if there is a lawful need.
  • If a key is lost by accident, the damage is small.
  • No one can secretly decode messages.
  • The system can be adapted as attackers find ways to game it.


  • More complex than a single key or single source for all keys. It will break more often.
  • Pretty expensive.
  • Judges need to be trained to understand what those keys mean.
  • Keys will be in more hands, creating more points of attack.

Always remember that in a democracy, the law isn’t about justice but balancing demands. There are people afraid that embarrassing details of their private communicate will be exposed as well as people trying to cover the tracks of a crime.

Right now, there is no better way to determine which communication needs to be cracked open than a normal court case.


If we used one or a few keys to encrypt everything (just because it’s easier), that would put a huge attraction on this data. Criminals will go to great lengths to steal those. If there are many keys, each one of them becomes less important. The amount of damage each key can cause must be smaller in this case. It would also mean they would have to steal many keys which would raise chances to get caught.

I was wondering if one key per month would be enough but there is really no technical reason to create so few. We have the infrastructure to create one every few seconds but that might be overkill. Once per day or maybe once per hour feels like a sweet spot. Note: When the technical framework has been set up, it should be easy to configure it to a different interval.

If we spread the keys over several organizations, an attack on one of them doesn’t compromise everyone. Also, software developers and users can move around, making it harder for unlawful espionage to track them.

Police officers and secret services should not be left alone with the decision what they can watch. Individuals make mistakes. That’s one reason why you talk to a friend when you make important decisions. Therefore, the keys should be in the hands of the law.

The law isn’t perfect. My thoughts are that we would use the perfect system if it existed. Since we’re using the law, the perfect solution probably doesn’t exist or it doesn’t exist, yet. In either case, using court rulings is the best solution we have right now to balance conflicting demands. The keys could be confiscated when the case is started and destroyed when the case is closed to avoid losing access halfway through the proceedings.

Mistakes will happen. Systems will break, keys will be lost, important messages will become indecipherable, criminals will attack the system, idiots will put keys on public network drives. Is there a way that this can be avoided? I doubt it. Therefore, I try to design a system which shows a certain resilience against problems to contain the damage.

For example, a chat app can request keys from its source. If that fails, it has options:

  1. Use a previous key
  2. Log an error in another system which monitors health of the key sources
  3. Automatically ask a different source
  4. Tell the user about it and refuse to work
  5. Let the user chose a different source

Spider-Man PS4

16. September, 2018
Spider-Man is currently one of the best and worst games for the PS4. Visually, it’s stunning. Swinging through the city is amazing. Different city parts are replicated in great detail, people are going to work, hailing taxis, using the tube. Missions are varied and complex. You get the collect air samples, detox areas, fight infections of animals, help the police with crime and tech problems. Well done, Insomniac. But. The fights. I’m playing on “friendly” (the easiest game mode) and I die about every 30 seconds in a fight. Enemies surround me and dead. I mash all the buttons but after some minutes of pure frustration, I abort the mission because I clearly can’t do it. No, I’m not talking about the boss fights, I’m talking about the usual street brawls. Apparently Spidey has tons of moves but he stumbles around like a drunk cat, collecting all the bullets, always getting stuck somewhere, L2+R2 rarely finds a target and if it does, they just shot me down from a distance. In Batman games, you could hide in a corner and collect your wits, not so here. I hit an enemy while someone else bludgeons my head with an iron while two or three colleagues use their machine guns on me and I die in a nice exploding cloud of a rocket. While I try to wrestle a gun from an enemy, his 20 friends clobber me dead. I stay in a place for more than 2 seconds, dead. Another problem with the button combos: They don’t work and you have no clue why not. The game displays the combo to press and … nothing happens. You press the evade button during a fight, nothing happens. You press L1+R1 to pick up something to throw, you get interrupted. Or nothing happens. I’ve played a lot of Insomniac games in the past. Ratchet & Clank. Resistance. I can finish most of them. I finished Andromeda. Many Batman games. That’s why I think it’s not me, it’s the game. On top of that, it creates this fake urgency – you can complete most missions at your leisure, no matter how panicked the voices are. So. If you like to be frustrated, if you love to learn 50 button combinations just to advance to the next level, the game is for you. For everyone else, wait for the play-through on Youtube.

The Benevolent AI

1. August, 2018

There is a lot of argument how AI will kill us all. Some argue that AI will see us a threat and wipe us out, just in case (the Skynet faction). Other argue AI will pamper us to death. The third group hopes that AI will just get bored and leave.

But how about the benevolent AI? Imagine a life which is fulfilling and demanding. It has highs and lows, disasters and triumphs. How about we create an AI with the goal to give such a life to everyone?

Of course, everyone has a different idea what such a life would be. That would make such an effort more complicated but not impossible.

It would also be very expensive to give everyone their perfect life. This factor depends on the amount of people (which will go down by itself) and how close we want everyone to get to the goal of “perfect”. In the beginning, the AI will both be immature and low on resources. Over time, it will learn from mistakes and people will start supporting the idea to give it more money and power when the idea works. So this is a problem which will resolve itself over time.

Then there are people who are never happy with what they have. People who can never get enough. Which I think translates to “the people around such persons don’t know how to teach them to be satisfied”. I think an AI could nudge those greedy people to become more complacent and enjoy their lives more.

This approach would put an end to mobbing. On one hand, people don’t like being mobbed, so the AI would have to put an end to it. On the other hand, I’m pretty sure the mobbers aren’t happy with their lives as well. So making them more satisfied might already be enough to put an end to mobbing.

Avoid Publishing SNAPSHOTs to Nexus

3. July, 2018

Once in a while I’m running into people who deploy SNAPSHOT versions of Maven dependencies to a company-wide Nexus server with a job on a CI server. This is usually a very bad idea, especially when using branches.

Scenario: Two developers, John and Mary, each working in their own branch. They push their branches, CI builds them and they end up on Nexus.

Problem: Nexus doesn’t know or care about branches. Whichever job finishes last wins.

Often, this is not a problem. Now let’s add another project B. B depends on A.

As long as B depends on a release of A, everything is fine.

Now, John needs to make some changes in A. So he updates the dependency in B to A-x.y.z-SNAPSHOT. Everything is still fine, since Mary still uses the latest release of A.

Then Mary also creates a feature branch in her clone of A. That still doesn’t break anything because Maven caches SNAPSHOTs for a day.

The next morning, John makes a change to B and builds it.

This build might break when Mary’s CI job finished last!

The problem here, which can go unnoticed for years, is that Maven silently downloaded Mary’s version of A onto John’s computer and used that to compile. John will see the source code from his branch of A but the binaries will be something else.

Eventually, one of them will make a small changes which affects the others project. They will see MethodNotFoundException or get strange compile errors while the source code (which isn’t affected by this) will look perfectly fine or unit tests will break in odd ways.

That is the main reason why you shouldn’t deploy SNAPSHOT branches to a shared Maven repository: It creates a small chance for subtle bugs which will take a long time to find since your mental model (“I see the source, this is what I get”) will be wrong.

You can get away with publishing the master branch to Nexus (i.e. only a single branch with SNAPSHOTs will ever be published to Nexus).

Note: If your CI server shares local Maven repositories between projects, your builds can fail on the CI server for the same reason. Configure your CI server for per-project local repositories and wipe them before the build to avoid such issues for sure.

Binding one Instance to Two Interfaces in Guice

15. June, 2018

Sometimes, you need to bind one instance to two interfaces in Guice, for example:

interface Foo { ... }

interface Bar extends Foo { ... }

class FooBarImpl implements Bar { ... }

Let’s imaging FooBarImpl is a stateful bean which is saved in a session scope:


This works when someone injects Bar but injecting Foo fails. There are two solutions for this: Bind Foo to Bar or use a provider method to transform the type.

Solution 1: Binding Interfaces


This will use the mapping for Bar to satisfy requests for Foo.

Solution 2: Provider Method

Provider methods are a nice way to build complex objects from bound instances. In our case, we can map the types like so:

public Foo fooProvider(Bar impl) {
    return impl;

Note: These approaches will put two keys into your scope but they will point to the same instance.

I’m Not a Robot (Rant)

31. December, 2017

Google’s “I’m not a robot” CAPTCHA is freaking me out.

I often spend minutes clicking stupid images only to be presented with more fucking images. It feels like it takes half an hour or more to just get the stupid thing to get out of the way so I can do whatever I came to do.

My main complaints:

  1. Is the frame of a street sign part of a street sign?
  2. Why do I get another page of images when I complete a task? Is the thing playing Sisyphus with me?
  3. Why does the thing suddenly change the game? First, I have to select pieces and click “Continue” and suddenly, it replaces pieces as I click and the button at the bottom behaves differently.
  4. Why can’t the thing remember me? Google and his friends know that it’s me! That’s their fucking business model! They make billions by tracking our movements on the web.
  5. The Google site boasts “Low friction, effortless interaction for your users.” There is no “File complaint” or support link anywhere. If it’s broken, guess who doesn’t care because they never hear about it? It’s one of these “it’s perfect – no one ever complained” situations.
  6. It puts me in an unbearable helpless situation where everything becomes a problem.

Just seeing the box turns me off by now. I’m starting to avoid web sites that use this. Patreon is about the last one where I force myself to endure the pain so I can help people. The support guys were nice and supportive, but there is little that they can do.

Stop on specific NullPointerException in Eclipse

20. December, 2017

TL;DR: Find the line where the exception occurs and then add a conditional breakpoint which checks the local variables for values that would trigger the exception.

In Eclipse, you can stop on any exception by using the menu Run -> “Add Java Exception Breakpoint…“.

That’s great but it doesn’t help when you want to stop on a certain exception on a certain line. It’s a big problem with code that uses exceptions for control flow – you could have thousands of those exceptions before you get to the one which you care about.

In my case, I had a NullPointerException in java.util.concurrent.ConcurrentHashMap:

    public V get(Object key) {
        Node<K,V>[] tab; Node<K,V> e, p; int n, eh; K ek;
        int h = spread(key.hashCode()); <-------- key is null

I tried to add a conditional breakpoint here with the condition key == null but Eclipse complained that it couldn’t compile the expression (probably missing debug information).

The method was called from Jetty’s ClassInheritanceHandler, so I added a conditional breakpoint there.

That’s another reason to copy method results into local variables before using them.

%d bloggers like this: