use of org.eclipse.persistence.internal.libraries.asm.Attribute in project eclipselink by eclipse-ee4j.
the class MetadataAsmFactory method buildClassMetadata.
/**
* Build the class metadata for the class name using ASM to read the class
* byte codes.
*/
protected void buildClassMetadata(MetadataClass metadataClass, String className, boolean isLazy) {
ClassMetadataVisitor visitor = new ClassMetadataVisitor(metadataClass, isLazy);
InputStream stream = null;
try {
String resourceString = className.replace('.', '/') + ".class";
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
final String f_resourceString = resourceString;
stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
@Override
public InputStream run() {
return m_loader.getResourceAsStream(f_resourceString);
}
});
} else {
stream = m_loader.getResourceAsStream(resourceString);
}
ClassReader reader = new ClassReader(stream);
Attribute[] attributes = new Attribute[0];
reader.accept(visitor, attributes, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
} catch (IllegalArgumentException iae) {
// class was probably compiled with some newer than officially
// supported and tested JDK
// in such case log a warning and try to re-read the class
// without class version check
SessionLog log = getLogger().getSession() != null ? getLogger().getSession().getSessionLog() : AbstractSessionLog.getLog();
if (log.shouldLog(SessionLog.WARNING, SessionLog.METADATA)) {
SessionLogEntry entry = new SessionLogEntry(getLogger().getSession(), SessionLog.WARNING, SessionLog.METADATA, iae);
entry.setMessage(ExceptionLocalization.buildMessage("unsupported_classfile_version", new Object[] { className }));
log.log(entry);
}
if (stream != null) {
try {
ClassReader reader = new EclipseLinkClassReader(stream);
Attribute[] attributes = new Attribute[0];
reader.accept(visitor, attributes, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
} catch (Exception e) {
// our fall-back failed, this is severe
if (log.shouldLog(SessionLog.SEVERE, SessionLog.METADATA)) {
SessionLogEntry entry = new SessionLogEntry(getLogger().getSession(), SessionLog.SEVERE, SessionLog.METADATA, e);
entry.setMessage(ExceptionLocalization.buildMessage("unsupported_classfile_version", new Object[] { className }));
log.log(entry);
}
addMetadataClass(getVirtualMetadataClass(className));
}
} else {
addMetadataClass(getVirtualMetadataClass(className));
}
} catch (Exception exception) {
SessionLog log = getLogger().getSession() != null ? getLogger().getSession().getSessionLog() : AbstractSessionLog.getLog();
if (log.shouldLog(SessionLog.FINEST, SessionLog.METADATA)) {
log.logThrowable(SessionLog.FINEST, SessionLog.METADATA, exception);
}
addMetadataClass(getVirtualMetadataClass(className));
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException ignore) {
// Ignore.
}
}
}
Aggregations