Fix EventBus when used with Byte.MAX_PRIORITY - closes #910. Also includes additional unit test cases to cover any future regressions.
This commit is contained in:
parent
eec3c09c32
commit
db7f3c770d
@ -178,7 +178,11 @@ public class EventBus
|
|||||||
if ( handlersByPriority != null )
|
if ( handlersByPriority != null )
|
||||||
{
|
{
|
||||||
List<EventHandlerMethod> handlersList = new ArrayList<>( handlersByPriority.size() * 2 );
|
List<EventHandlerMethod> handlersList = new ArrayList<>( handlersByPriority.size() * 2 );
|
||||||
for ( byte value = Byte.MIN_VALUE; value < Byte.MAX_VALUE; value++ )
|
|
||||||
|
// Either I'm really tired, or the only way we can iterate between Byte.MIN_VALUE and Byte.MAX_VALUE inclusively,
|
||||||
|
// with only a byte on the stack is by using a do {} while() format loop.
|
||||||
|
byte value = Byte.MIN_VALUE;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
Map<Object, Method[]> handlersByListener = handlersByPriority.get( value );
|
Map<Object, Method[]> handlersByListener = handlersByPriority.get( value );
|
||||||
if ( handlersByListener != null )
|
if ( handlersByListener != null )
|
||||||
@ -192,7 +196,7 @@ public class EventBus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while ( value++ < Byte.MAX_VALUE );
|
||||||
byEventBaked.put( eventClass, handlersList.toArray( new EventHandlerMethod[ handlersList.size() ] ) );
|
byEventBaked.put( eventClass, handlersList.toArray( new EventHandlerMethod[ handlersList.size() ] ) );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
@ -19,10 +19,17 @@ public class EventPriorityTest
|
|||||||
Assert.assertEquals( 0, latch.getCount() );
|
Assert.assertEquals( 0, latch.getCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = Byte.MIN_VALUE)
|
||||||
|
public void onMinPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 5, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onLowestPriority(PriorityTestEvent event)
|
public void onLowestPriority(PriorityTestEvent event)
|
||||||
{
|
{
|
||||||
Assert.assertEquals( 5, latch.getCount() );
|
Assert.assertEquals( 4, latch.getCount() );
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +42,13 @@ public class EventPriorityTest
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onHighestPriority(PriorityTestEvent event)
|
public void onHighestPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 2, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = Byte.MAX_VALUE)
|
||||||
|
public void onMaxPriority(PriorityTestEvent event)
|
||||||
{
|
{
|
||||||
Assert.assertEquals( 1, latch.getCount() );
|
Assert.assertEquals( 1, latch.getCount() );
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
Loading…
Reference in New Issue
Block a user