Set klass to document klass when nil. [ fix #2774 ]