Skip to content

Fix for undetected circular definitions when resolving properties. #249

merged 6 commits into from Jun 26, 2014

2 participants


PropertyTask::resolveAllProperties checks for circularly defined properties by comparing the property being resolved against each new one added. This way, a circular chain like in this .properties file is detected:


However it fails to detect this one:


It will forever check A==B and A==C without ever breaking out.

With this commit, it checks against all properties used to resolve the current one. I'm almost sure this will detect any circular definition. It fixes the hangs I found anyway.

HuffAndPuff added some commits Nov 22, 2013
@HuffAndPuff HuffAndPuff Added HangDetectorPropertyTask to the PropertyTask tests.
I want to add some tests that currently fail to detect a circular
reference, but running these tests (obviously) causes PHPUnit to
hang which is very unpleasant.

HangDetectorPropertyTask extends PropertyTask and uses a custom
HangDetectorProperties (extends Properties) that counts the number
of accesses. More than 100 is interpreted as an undetected circular
reference. Don't use big property sets when testing...
@HuffAndPuff HuffAndPuff Changed test3 to testCircularReferenceDetection and added data provider. c602d47
@HuffAndPuff HuffAndPuff Add two new PropertyTask tests where circular definition detection fa…

Below, A->B means resolves to B in some way, like A=xx${B}yy

Currently a chain like A->B->A will be detected in the
resolveAllProperties() function since we check each new property in the
chain against the property were trying to resolve.

This fails if we start to resolve A but the circular chain doesn't
involve A:

These two tests reflect that.
@HuffAndPuff HuffAndPuff For consistence, it's circular "Definition", not "Reference". 6fc0be1
@HuffAndPuff HuffAndPuff Fix for the tests testCircularDefinition1 and testCircularDefinition2.
In resolveAllProperties() we remember which properties from $props have
been used to resolve the current property. If the same property appears
twice, we have a circular property definition.

This will detect chains like A resolves to B resolves to C resolves to B...
@HuffAndPuff HuffAndPuff Forgot to add file... 200cfbe

Dunno why the test fails, seems unrelated to my changes.

Anyways, ProjectConfiguratior::replaceProperties could use a similar mechanism to detect infinite loops instead of the current limit 5 of iterations. There you can either throw an error or log a warning.

Is there an specific reason for silently ignoring infinite loops like this or is a something like this desired? I could add it if requested.

@mrook mrook merged commit 002958f into phingofficial:master Jun 26, 2014

1 check failed

Details default The Travis CI build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.