Bug 1030262

Summary: Code typo in "Load a Class File From the Class Loader" doc
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Pavel Jelinek <pjelinek>
Component: DocumentationAssignee: sgilda
Status: CLOSED CURRENTRELEASE QA Contact: Russell Dickenson <rdickens>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.2.0CC: david.lloyd, twells
Target Milestone: GAKeywords: Documentation, Triaged
Target Release: EAP 6.2.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Build Name: 14875, Development Guide-6.2-1 Build Date: 12-11-2013 07:06:39 Topic ID: 24376-549765 [Specified]
Last Closed: 2014-02-24 20:15:57 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Pavel Jelinek 2013-11-14 09:10:51 UTC
Title: Programmatically Load Classes and Resources in a Deployment

Suggestions for improvement:
In the "Load a Class File From the Class Loader" subsection change this: 

InputStream inputStream = TargetClass.class.getResourceAsStream(TargetClass.class.getSimpleName().replace('.', '/') + ".class");

to: 

InputStream inputStream = TargetClass.class.getResourceAsStream(TargetClass.class.getCanonicalName().replace('.', '/') + ".class");

Comment 1 David M. Lloyd 2013-11-14 16:36:26 UTC
This is actually incorrect.  It *would* be correct if the left hand argument were a class loader, but because it's a class, it will already search in the class' current directory, thus only the simple name should be given.

However this does raise a different issue: the .replace() is not actually needed here because there will never be path separator components.

Comment 2 sgilda 2013-11-14 16:42:17 UTC
I will change the example to:

InputStream inputStream = TargetClass.class.getResourceAsStream(TargetClass.class.getSimpleName() + ".class");

Comment 4 sgilda 2013-11-15 13:10:01 UTC
David reviewed the docbuilder version and said it looks much better. Moving to modified.

Comment 5 sgilda 2013-11-19 15:10:24 UTC
This is not yet staged.