Skip to content

Commit

Permalink
chore: Remove accidental references to non Java 1.6 classes
Browse files Browse the repository at this point in the history
Fixes #388.
  • Loading branch information
rhuss committed Mar 21, 2019
1 parent cdc20f8 commit 4e669b9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
@@ -1,8 +1,8 @@
package org.jolokia.converter.json;

import java.beans.Transient;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand Down Expand Up @@ -208,13 +208,22 @@ private List<String> extractBeanAttributes(Object pValue) {
if (!Modifier.isStatic(method.getModifiers()) &&
!IGNORE_METHODS.contains(method.getName()) &&
!isIgnoredType(method.getReturnType()) &&
!method.isAnnotationPresent(Transient.class)) {
!hasAnnotation(method, "java.beans.Transient")) {
addAttributes(attrs, method);
}
}
return attrs;
}

private boolean hasAnnotation(Method method, String annotation) {
for (Annotation anno : method.getAnnotations()) {
if (anno.annotationType().getName().equals(annotation)) {
return true;
}
}
return false;
}

// Add attributes, which are taken from get methods to the given list
@SuppressWarnings("PMD.UnnecessaryCaseChange")
private void addAttributes(List<String> pAttrs, Method pMethod) {
Expand Down
8 changes: 4 additions & 4 deletions agent/core/src/main/java/org/jolokia/util/JolokiaCipher.java
Expand Up @@ -5,7 +5,7 @@
import javax.crypto.spec.SecretKeySpec;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.security.*;
import java.util.Random;

Expand Down Expand Up @@ -52,7 +52,7 @@ public JolokiaCipher(KeyHolder pKeyHolder) throws NoSuchAlgorithmException {
* @return the encoded password
*/
public String encrypt(final String pText) throws GeneralSecurityException {
byte[] clearBytes = pText.getBytes(StandardCharsets.UTF_8);
byte[] clearBytes = pText.getBytes(Charset.forName("UTF-8"));
byte[] salt = getSalt(SALT_SIZE);

Cipher cipher = createCipher(salt, Cipher.ENCRYPT_MODE);
Expand Down Expand Up @@ -91,7 +91,7 @@ public String decrypt(final String pEncryptedText) throws GeneralSecurityExcepti
Cipher cipher = createCipher(salt, Cipher.DECRYPT_MODE);
byte[] clearBytes = cipher.doFinal(encryptedBytes);

return new String(clearBytes, StandardCharsets.UTF_8);
return new String(clearBytes, Charset.forName("UTF-8"));
}

// =================================================================
Expand Down Expand Up @@ -149,7 +149,7 @@ private Cipher createCipher(byte[] salt, final int mode)
public interface KeyHolder { String getKey(); };

private byte[] getKeyAsBytes() {
return keyHolder.getKey().getBytes(StandardCharsets.UTF_8);
return keyHolder.getKey().getBytes(Charset.forName("UTF-8"));
}

private static class KeyHolderImpl implements KeyHolder {
Expand Down
18 changes: 18 additions & 0 deletions agent/core/src/test/java/java/beans/Transient.java
@@ -0,0 +1,18 @@
package java.beans;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* For testing purpose on Java 1.6
* @author roland
* @since 04.09.18
*/
@Target({METHOD})
@Retention(RUNTIME)
public @interface Transient {
boolean value() default true;
}
Expand Up @@ -268,5 +268,4 @@ public void setTransientValue(String transientValue) {
this.transientValue = transientValue;
}
}
}

}
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -750,6 +750,7 @@
</pluginManagement>
</build>
</profile>

<profile>
<id>disable-javadoc-lint</id>
<activation>
Expand Down

0 comments on commit 4e669b9

Please sign in to comment.