protected <T, K> T applyTrait( K core, Class<T> trait, Object value, boolean logical ) throws LogicalTypeInconsistencyException {
TraitFactory builder = TraitFactory.getTraitBuilderForKnowledgeBase( this.getKnowledgeRuntime().getKnowledgeBase() );
TraitableBean inner = makeTraitable( core, builder, logical );
boolean needsProxy = trait.isAssignableFrom( inner.getClass() );
boolean hasTrait = inner.hasTrait( trait.getName() );
boolean needsUpdate = needsProxy || core != inner;
BitSet boundary = inner.getCurrentTypeCode() != null ? (BitSet) inner.getCurrentTypeCode().clone() : null;
Collection<Key<Thing>> mostSpecificTraits = getTraitBoundary( inner, needsProxy, hasTrait, trait );
T thing = asTrait( core, inner, trait, needsProxy, hasTrait, needsUpdate, builder, logical );