Skip to content

Commit e03993e

Browse files
committed
No text in unsupportedOperationException; see #96
1 parent b5deb9b commit e03993e

File tree

6 files changed

+49
-55
lines changed

6 files changed

+49
-55
lines changed

src/main/java/com/helger/jcodemodel/JCodeModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public static JCodeModel createUnified ()
274274
catch (final JCodeModelException e)
275275
{
276276
// should not happen
277-
throw new UnsupportedOperationException ("This is the famous 'should never occur' error", e);
277+
throw new UnsupportedOperationException (e);
278278
}
279279
}
280280

@@ -1085,7 +1085,7 @@ public static JCodeModel copySerial (final JCodeModel source)
10851085
}
10861086
catch (final IOException | ClassNotFoundException e)
10871087
{
1088-
throw new UnsupportedOperationException ("Failed to write code model to string", e);
1088+
throw new UnsupportedOperationException (e);
10891089
}
10901090
}
10911091

src/main/java/com/helger/jcodemodel/JResourceDir.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public class JResourceDir implements IJOwned, Serializable
105105
* If a part of the package name is not a valid filename part.
106106
*/
107107
protected JResourceDir (@Nonnull final JCodeModel aOwner,
108-
@Nullable final JResourceDir aParentDir,
109-
@Nonnull final String sName) throws JInvalidFileNameException
108+
@Nullable final JResourceDir aParentDir,
109+
@Nonnull final String sName) throws JInvalidFileNameException
110110
{
111111
ValueEnforcer.notNull (sName, "Name");
112112
ValueEnforcer.notNull (aOwner, "CodeModel");
@@ -324,7 +324,7 @@ static JResourceDir root (@Nonnull final JCodeModel aOwner)
324324
catch (final JInvalidFileNameException e)
325325
{
326326
// should not happen
327-
throw new UnsupportedOperationException ("catch this", e);
327+
throw new UnsupportedOperationException (e);
328328
}
329329
}
330330
}

src/main/java/com/helger/jcodemodel/compile/ClassLoaderFileManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public JavaFileObject getJavaFileForOutput (final Location location,
221221
}
222222
catch (final Exception e)
223223
{
224-
throw new UnsupportedOperationException ("while creating code for " + className, e);
224+
throw new UnsupportedOperationException (e);
225225
}
226226
return ret;
227227
}

src/main/java/com/helger/jcodemodel/compile/DynamicClassLoader.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@
5757
/**
5858
* class loader that allows dynamic classes and resources.
5959
* <p>
60-
* add class models using {@link #setCode(CompiledCodeJavaFile)} , add resources
61-
* using {@link #addResources(Map)}; then you can use it as a normal
62-
* classloader, eg {@link ClassLoader#loadClass(String)} or
63-
* {@link ClassLoader#getResource(String)}
60+
* add class models using {@link #setCode(CompiledCodeJavaFile)} , add resources using
61+
* {@link #addResources(Map)}; then you can use it as a normal classloader, eg
62+
* {@link ClassLoader#loadClass(String)} or {@link ClassLoader#getResource(String)}
6463
* </p>
6564
*/
6665
public class DynamicClassLoader extends ClassLoader
@@ -69,9 +68,9 @@ public class DynamicClassLoader extends ClassLoader
6968
private final Map <String, NonBlockingByteArrayOutputStream> m_aCustomResources = new HashMap <> ();
7069

7170
/**
72-
* internal url handler that generates url to load inside its own resources,
73-
* if exists. It overloads the openConnection to provide an input stream if a
74-
* corresponding bytearray is found for the resource.
71+
* internal url handler that generates url to load inside its own resources, if exists. It
72+
* overloads the openConnection to provide an input stream if a corresponding bytearray is found
73+
* for the resource.
7574
*/
7675
private final URLStreamHandler m_aURLStreamHandler = new URLStreamHandler ()
7776
{
@@ -104,8 +103,7 @@ public InputStream getInputStream () throws IOException
104103
* create a class loader with its parent.
105104
*
106105
* @param parent
107-
* the classloader to fall back when a resource or class definition
108-
* can't be found.
106+
* the classloader to fall back when a resource or class definition can't be found.
109107
*/
110108
public DynamicClassLoader (final ClassLoader parent)
111109
{
@@ -127,8 +125,7 @@ public void setCode (@Nonnull final CompiledCodeJavaFile cc)
127125
* get the bytecode for a given class name.
128126
*
129127
* @param fullClassName
130-
* the full name of the class, including its package, eg
131-
* java.lang.String
128+
* the full name of the class, including its package, eg java.lang.String
132129
* @return the existing compiledCode for that class, or null.
133130
*/
134131
public CompiledCodeJavaFile getCode (final String fullClassName)
@@ -171,7 +168,7 @@ protected URL findResource (final String sName)
171168
}
172169
catch (final MalformedURLException e)
173170
{
174-
throw new UnsupportedOperationException ("catch this", e);
171+
throw new UnsupportedOperationException (e);
175172
}
176173

177174
return super.findResource (sName);

src/main/java/com/helger/jcodemodel/compile/MemoryCodeWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public ESuccess compile (@Nonnull final DynamicClassLoader aDynamicClassLoader)
188188
}
189189
catch (final Exception e1)
190190
{
191-
throw new UnsupportedOperationException ("catch this exception", e1);
191+
throw new UnsupportedOperationException (e1);
192192
}
193193
else
194194
aNonJava.put (e.getKey (), e.getValue ());
@@ -222,7 +222,7 @@ public ESuccess compile (@Nonnull final DynamicClassLoader aDynamicClassLoader)
222222
}
223223
catch (final Exception e1)
224224
{
225-
throw new UnsupportedOperationException ("catch this exception", e1);
225+
throw new UnsupportedOperationException (e1);
226226
}
227227
aDynamicClassLoader.addResources (aNonJava);
228228
return ESuccess.SUCCESS;
@@ -264,7 +264,7 @@ public static MemoryCodeWriter from (@Nonnull final JCodeModel jcm)
264264
}
265265
catch (final IOException e)
266266
{
267-
throw new UnsupportedOperationException ("catch this exception", e);
267+
throw new UnsupportedOperationException (e);
268268
}
269269
return codeWriter;
270270
}

src/test/java/com/helger/jcodemodel/ModelCopyTest.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
import com.helger.jcodemodel.writer.StringCodeWriter;
1212

1313
/**
14-
* abstract method for a test of copying. Such a test consist in creating a source codemodel, copying it, check the
15-
* equality of the representation of the copy and the source ; then apply several modifications on the source, each
16-
* result in a model varying from the copy ; then apply those modifications to the copy, which in the end should have
17-
* the same representation as the source.<br />
18-
*
14+
* abstract method for a test of copying. Such a test consist in creating a source codemodel,
15+
* copying it, check the equality of the representation of the copy and the source ; then apply
16+
* several modifications on the source, each result in a model varying from the copy ; then apply
17+
* those modifications to the copy, which in the end should have the same representation as the
18+
* source.<br />
1919
* This class defines
2020
* <ul>
2121
* <li>{@link #execute()} that should be called in the test,</li>
2222
* <li>{@link #createCM()} that creates a base code model,</li>
2323
* <li>{@link #copy(JCodeModel)} that defines how to copy a {@link JCodeModel},</li>
2424
* <li>{@link #represent(JCodeModel)} to make a representation of a codemodel,</li>
25-
* <li> {@link #modifications()} that lists a series of modifications to apply.</li>
25+
* <li>{@link #modifications()} that lists a series of modifications to apply.</li>
2626
* </ul>
2727
*
2828
* @author glelouet
@@ -33,15 +33,15 @@ public class ModelCopyTest
3333
@Test
3434
public void execute ()
3535
{
36-
JCodeModel cm = createCM ();
37-
JCodeModel copy = copy (cm);
36+
final JCodeModel cm = createCM ();
37+
final JCodeModel copy = copy (cm);
3838
Assert.assertEquals (represent (cm), represent (copy));
39-
for (Consumer <JCodeModel> m : modifications ())
39+
for (final Consumer <JCodeModel> m : modifications ())
4040
{
4141
m.accept (cm);
4242
Assert.assertNotEquals (represent (cm), represent (copy));
4343
}
44-
for (Consumer <JCodeModel> m : modifications ())
44+
for (final Consumer <JCodeModel> m : modifications ())
4545
m.accept (copy);
4646
Assert.assertEquals (represent (cm), represent (copy));
4747
}
@@ -50,65 +50,62 @@ protected JCodeModel createCM ()
5050
{
5151
try
5252
{
53-
JCodeModel ret = new JCodeModel ();
53+
final JCodeModel ret = new JCodeModel ();
5454

5555
// create an interface IMyClass with method default String string(){return "yes";}
56-
JDefinedClass itf = ret._class ("my.pckg.IMyClass", EClassType.INTERFACE);
57-
JMethod methd = itf.method (JMod.PUBLIC | JMod.DEFAULT, ret.ref (String.class), "string");
56+
final JDefinedClass itf = ret._class ("my.pckg.IMyClass", EClassType.INTERFACE);
57+
final JMethod methd = itf.method (JMod.PUBLIC | JMod.DEFAULT, ret.ref (String.class), "string");
5858
methd.body ()._return (JExpr.lit ("yes"));
5959

6060
// create an implementation of that interface, for which toString() returns the string();
61-
JDefinedClass imp = itf._package ()._class (JMod.PUBLIC, "Impl")._implements (itf);
61+
final JDefinedClass imp = itf._package ()._class (JMod.PUBLIC, "Impl")._implements (itf);
6262
imp.method (JMod.PUBLIC, ret.ref (String.class), "toString").body ()._return (JExpr.invoke (methd));
6363
return ret;
6464
}
65-
catch (JCodeModelException e)
65+
catch (final JCodeModelException e)
6666
{
67-
throw new UnsupportedOperationException ("catch this", e);
67+
throw new UnsupportedOperationException (e);
6868
}
6969
}
7070

71-
protected JCodeModel copy (JCodeModel source)
71+
protected JCodeModel copy (final JCodeModel source)
7272
{
7373
return source.copy ();
7474
}
7575

76-
protected String represent (JCodeModel target)
76+
protected String represent (final JCodeModel target)
7777
{
7878
return StringCodeWriter.represent (target);
7979
}
8080

8181
public Collection <Consumer <JCodeModel>> modifications ()
8282
{
83-
return Arrays.asList (cm ->
84-
{
83+
return Arrays.asList (cm -> {
8584
try
8685
{
8786
cm._class (JMod.PUBLIC, "MyClass");
8887
}
89-
catch (JCodeModelException e)
88+
catch (final JCodeModelException e)
9089
{
91-
throw new UnsupportedOperationException ("catch this", e);
90+
throw new UnsupportedOperationException (e);
9291
}
93-
}, cm ->
94-
{
95-
JDefinedClass cl = cm._getClass ("my.pckg.IMyClass");
92+
}, cm -> {
93+
final JDefinedClass cl = cm._getClass ("my.pckg.IMyClass");
9694
cl.method (JMod.DEFAULT, cm.BOOLEAN, "yes").body ()._return (JExpr.TRUE);
97-
}, cm ->
98-
{
95+
}, cm -> {
9996
try
10097
{
101-
JDefinedClass cl = cm._getClass ("my.pckg.IMyClass");
102-
JDefinedClass newcl = cl._class (JMod.STATIC | JMod.PUBLIC, "InternalIntClass");
103-
JFieldVar fld = newcl.field (JMod.PRIVATE, cm.INT, "intField");
104-
JMethod cons = newcl.constructor (JMod.PUBLIC);
105-
JVar consParam = cons.param (cm.INT, "number");
98+
final JDefinedClass cl = cm._getClass ("my.pckg.IMyClass");
99+
final JDefinedClass newcl = cl._class (JMod.STATIC | JMod.PUBLIC, "InternalIntClass");
100+
final JFieldVar fld = newcl.field (JMod.PRIVATE, cm.INT, "intField");
101+
final JMethod cons = newcl.constructor (JMod.PUBLIC);
102+
final JVar consParam = cons.param (cm.INT, "number");
106103
cons.body ().assign (fld, consParam);
107104
newcl.method (JMod.PUBLIC, cm.INT, "incr").body ()._return (JExpr.preincr (fld));
108105
}
109-
catch (JCodeModelException e)
106+
catch (final JCodeModelException e)
110107
{
111-
throw new UnsupportedOperationException ("catch this", e);
108+
throw new UnsupportedOperationException (e);
112109
}
113110
});
114111
}

0 commit comments

Comments
 (0)