EA-38947 (assert: JavaParserUtil.parseFragment)

This commit is contained in:
Bas Leijdekkers
2012-09-05 15:05:16 +02:00
parent c53f245217
commit 4fc4ba75b6
3 changed files with 38 additions and 3 deletions
@@ -52,6 +52,10 @@ public class ExternalizableWithoutPublicNoArgConstructorInspection extends BaseI
final PsiMethod constructor = (PsiMethod)infos[1];
if (constructor == null) {
final PsiClass aClass = (PsiClass)infos[0];
if (aClass instanceof PsiAnonymousClass) {
// can't create constructor for anonymous class
return null;
}
return new DelegatingFix(new AddDefaultConstructorFix(aClass, PsiModifier.PUBLIC));
}
else {
@@ -73,6 +77,7 @@ public class ExternalizableWithoutPublicNoArgConstructorInspection extends BaseI
private static class MakeConstructorPublicFix extends InspectionGadgetsFix {
@Override
@NotNull
public String getName() {
return InspectionGadgetsBundle.message("make.constructor.public");
@@ -31,4 +31,30 @@ class eImpl2 extends e {
public void writeExternal(ObjectOutput out) throws IOException {
}
}
class AnonymousTest {
public static void main(String[] args) throws IOException, ClassNotFoundException {
final String h = "Hello World";
final Externalizable externalizable = new Externalizable() {
private String string = h;
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(string);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
string = in.readUTF();
}
};
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(externalizable);
out.close();
final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
final Object o = in.readObject();
System.out.println("o = " + o);
}
}
@@ -3,7 +3,6 @@
<problem>
<file>ExternalizableWithoutPublicNoArgConstructor.java</file>
<line>9</line>
<module>test_5975879954938100914</module>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Externalizable class without public no-arg constructor</problem_class>
<description>Externalizable class &lt;code&gt;eImpl&lt;/code&gt; has no public no-arg constructor</description>
</problem>
@@ -11,7 +10,6 @@
<problem>
<file>ExternalizableWithoutPublicNoArgConstructor.java</file>
<line>16</line>
<entry_point TYPE="class" FQNAME="com.siyeh.igtest.serialization.externalizable_without_public_no_arg_constructor.eImpl1" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Externalizable class without public no-arg constructor</problem_class>
<description>Externalizable class &lt;code&gt;eImpl1&lt;/code&gt; has no public no-arg constructor</description>
</problem>
@@ -19,8 +17,14 @@
<problem>
<file>ExternalizableWithoutPublicNoArgConstructor.java</file>
<line>24</line>
<entry_point TYPE="class" FQNAME="com.siyeh.igtest.serialization.externalizable_without_public_no_arg_constructor.eImpl2" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Externalizable class without public no-arg constructor</problem_class>
<description>Externalizable class &lt;code&gt;eImpl2&lt;/code&gt; has no public no-arg constructor</description>
</problem>
<problem>
<file>ExternalizableWithoutPublicNoArgConstructor.java</file>
<line>37</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Externalizable class without public no-arg constructor</problem_class>
<description>Externalizable class &lt;code&gt;Externalizable&lt;/code&gt; has no public no-arg constructor #loc</description>
</problem>
</problems>