考虑这个示例类,
class TargetClass {
private static String SENSITIVE_DATA = "sw0rdfish";
private static String getSensitiveData() {
return SENSITIVE_DATA;
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,
import java.lang.reflect.Method;
public class ClassPiercing {
public static void main(String... args) throws Exception {
Class targetClass = Class.forName("TargetClass");
Method[] methods = targetClass.getDeclaredMethods();
methods[0].setAccessible(true);
String sensitiveData = (String)methods[0].invoke(null, null);
System.out.println("Sensitive Data: " + sensitiveData);
}
}
Run Code Online (Sandbox Code Playgroud)
输出是,
Sensitive Data: sw0rdfish
Run Code Online (Sandbox Code Playgroud)
这很危险.我该如何防止这种情况发生?
我知道应该在静态环境中访问睡眠.但是我需要更多的输入,所以我可以向管理层辩护.我正在处理的大多数遗留代码现在使用新的Thread().sleep而不是Thread.sleep.
这有多糟糕?
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
与此相比?
for (int c = 0; c < 5; c++) {
Thread.sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
final long start = System.currentTimeMillis();
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("===========================");
}
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
System.out.println("Time elapsed: " …Run Code Online (Sandbox Code Playgroud) 我在String的ArrayList中没有特定顺序的这些字符串但是当我调用Collections.sort(listReference)时,排序的结果是不正确的,为什么10和11(最后2个字符)在07,08,09之前出现?
12880 20090506054200001
12880 20090506054200002
12880 20090513070200003
12880 20090513070200004
12880 20090520202600005
12880 20090520202600006
12880 20090520232900010
12880 20090520232900011
12880 20090520232900007
12880 20090520232900008
12880 20090520232900009
Run Code Online (Sandbox Code Playgroud) 包含哈瓦那(UTF-8)的XML被发送到服务A.
服务A将其发送给服务B.
该字符串被编码为å"ç"|é,£(ISO-8859-1).
我怎么把它编码回哈瓦那?考虑到Java中的所有字符串都是UTF-16.服务B必须将其比作哈瓦那不是å"ç"|é,£.
谢谢.
这是一个Java问题.
将a转换List<?>为a 的最快方法是List<ObjectType>什么?我知道这可以通过迭代,请排除该选项.
迭代的例子,
final List<ObjectType> targetList = new ArrayList<ObjectType>();
// API returns List<?> so I have no choice.
List<?> resultList = resultSet.getResults();
// This is slow. Average list size is 500,000 elements.
while (resultList != null && !resultList.isEmpty()) {
for (final Object object : resultList) {
final ObjectType objectType = (ObjectType) object;
targetList.add(objectType);
}
resultSet = someService.getNext(resultSet);
resultList = resultSet.getList();
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我已经为以下所有设置了一致的命名空间(http://somenamespace.com/2012/10/):
但是我在服务日志(.svclog)文件上收到此错误.有人可以开导我这个吗?我已经咨询了几个网站,但无济于事.
这是一个很好的参考:http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/ee11d86f-f25c-4284-8f51-b1f035346cb3/
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131074</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2013-01-04T06:57:48.7620812Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{eadc96c2-323f-41df-bc3d-df56367dda52}" />
<Execution ProcessName="w3wp" ProcessID="2088" ThreadID="54" />
<Channel />
<Computer>SOMECOMPUTER007</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.EventLog.aspx</TraceIdentifier>
<Description>Wrote to the EventLog.</Description>
<AppDomain>/LM/W3SVC/1/ROOT/SomeApplication-1-130017541311895789</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
<CategoryID.Name>EventLogCategory</CategoryID.Name>
<CategoryID.Value>7</CategoryID.Value>
<InstanceID.Name>EventId</InstanceID.Name>
<InstanceID.Value>3221356549</InstanceID.Value>
<Value0>System.ArgumentException: The 'http://somenamespace.com/2012/10/' namespace is not defined.
at System.Xml.XmlWriter.WriteQualifiedName(String localName, String ns)
at System.Runtime.Serialization.XmlWriterDelegator.WriteAttributeQualifiedName(String attrPrefix, XmlDictionaryString attrName, XmlDictionaryString attrNs, XmlDictionaryString name, XmlDictionaryString ns) …Run Code Online (Sandbox Code Playgroud) java ×5
arraylist ×1
arrays ×1
c# ×1
collections ×1
constraints ×1
encoding ×1
generics ×1
list ×1
oop ×1
optimization ×1
profiling ×1
security ×1
soap ×1
sorting ×1
wcf ×1
web-services ×1