Bug 1030262 - Code typo in "Load a Class File From the Class Loader" doc
Summary: Code typo in "Load a Class File From the Class Loader" doc
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: Documentation
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: GA
: EAP 6.2.1
Assignee: sgilda
QA Contact: Russell Dickenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-11-14 09:10 UTC by Pavel Jelinek
Modified: 2014-09-29 18:30 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
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
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1024853 0 unspecified CLOSED Enhancements to "Programmatically Load Classes and Resources in a Deployment" doc 2021-02-22 00:41:40 UTC

Internal Links: 1024853

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.


Note You need to log in before you can comment on or make changes to this bug.